Repository: spack/spack

Issue:
spack url parse offset incorrect for SourceForge downloads
SourceForge downloads have an optional `/download` suffix. This appears to be messing up the offset reported to `spack url parse`:
```
$ spack url parse https://sourceforge.net/projects/argtable/files/argtable/argtable-2.13/argtable2-13.tar.gz/download
==> Parsing URL: https://sourceforge.net/projects/argtable/files/argtable/argtable-2.13/argtable2-13.tar.gz/download

==> Matched version regex  3: r'^[a-zA-Z+-]*(\\d[\\da-zA-Z-]*)$'
==> Matched  name   regex  7: r'^([A-Za-z\\d+\\._-]+)$'

==> Detected:
    https://sourceforge.net/projects/argtable/files/argtable/argtable-2.13/argtable2-13.tar.gz/download
                                                                   --------~~~~
    name:    argtable
    version: 2-13

==> Substituting version 9.9.9b:
    https://sourceforge.net/projects/argtable/files/argtable/argtable-2.13/argtable9.9.9b.tar.gz/download
                                                                   --------~~~~~~
```
```
$ spack url parse https://sourceforge.net/projects/argtable/files/argtable/argtable-2.13/argtable2-13.tar.gz
==> Parsing URL: https://sourceforge.net/projects/argtable/files/argtable/argtable-2.13/argtable2-13.tar.gz

==> Matched version regex  3: r'^[a-zA-Z+-]*(\\d[\\da-zA-Z-]*)$'
==> Matched  name   regex  7: r'^([A-Za-z\\d+\\._-]+)$'

==> Detected:
    https://sourceforge.net/projects/argtable/files/argtable/argtable-2.13/argtable2-13.tar.gz
                                                                           --------~~~~
    name:    argtable
    version: 2-13

==> Substituting version 9.9.9b:
    https://sourceforge.net/projects/argtable/files/argtable/argtable-2.13/argtable9.9.9b.tar.gz
                                                                           --------~~~~~~
```
The URL is still substituted correctly, so this is a pretty minor issue. But I wanted to record it before I forget. I'll try to fix this tomorrow.


Discussion:

Resolving patch:
diff --git a/lib/spack/spack/url.py b/lib/spack/spack/url.py
--- a/lib/spack/spack/url.py
+++ b/lib/spack/spack/url.py
@@ -301,7 +301,8 @@ def split_url_extension(path):
     prefix, ext, suffix = path, '', ''
 
     # Strip off sourceforge download suffix.
-    match = re.search(r'((?:sourceforge\.net|sf\.net)/.*)(/download)$', path)
+    # e.g. https://sourceforge.net/projects/glew/files/glew/2.0.0/glew-2.0.0.tgz/download
+    match = re.search(r'(.*(?:sourceforge\.net|sf\.net)/.*)(/download)$', path)
     if match:
         prefix, suffix = match.groups()
 


Test patch:
diff --git a/lib/spack/spack/test/url_parse.py b/lib/spack/spack/test/url_parse.py
--- a/lib/spack/spack/test/url_parse.py
+++ b/lib/spack/spack/test/url_parse.py
@@ -160,6 +160,8 @@ def test_url_strip_name_suffixes(url, version, expected):
     ('sionlib', 30, '1.7.1', 59, 'http://apps.fz-juelich.de/jsc/sionlib/download.php?version=1.7.1'),
     # Regex in name
     ('voro++', 40, '0.4.6', 47, 'http://math.lbl.gov/voro++/download/dir/voro++-0.4.6.tar.gz'),
+    # SourceForge download
+    ('glew', 55, '2.0.0', 60, 'https://sourceforge.net/projects/glew/files/glew/2.0.0/glew-2.0.0.tgz/download'),
 ])
 def test_url_parse_offset(name, noffset, ver, voffset, path):
     """Tests that the name, version and offsets are computed correctly.