Commits

Jan-Jaap Driessen committed 7bc2c1b

The script_name is a fallback for computing library URLs. The base_url parameter should be honoured if it is provided.

Comments (0)

Files changed (2)

fanstatic/core.py

       also be set with the set_base_url method on a ``NeededResources``
       instance.
 
+    :param script_name: The script_name is a fallback for computing
+      library URLs. The base_url parameter should be honoured if
+      it is provided.
+
     :param publisher_signature: The name under which resource libraries
       should be served in the URL. By default this is ``fanstatic``, so
       URLs to resources will start with ``/fanstatic/``.
 
         :param library: A :py:class:`Library` instance.
         """
-        start = self._base_url or ''
-        if self._script_name:
-            # script_name typically starts with a '/', so we
-            # want to consume it early in order to avoid double forward slashes
-            # when joining the path segments later.
-            start += self._script_name
-
-        path = [start]
+        # The script_name is a fallback and base_url should be honoured
+        # if it is provided.
+        path = [self._base_url or self._script_name or '']
         if self._publisher_signature:
             path.append(self._publisher_signature)
         path.append(library.name)

fanstatic/test_core.py

 def test_library_url_script_name_base_url():
     foo = Library('foo', '')
     needed = NeededResources(
-        base_url='http://static.example.com', script_name='/root')
-    assert needed.library_url(foo) == \
-        'http://static.example.com/root/fanstatic/foo'
+        script_name='/root', base_url="http://example.com/something")
+
+    # base_url is set so script_name should be ignored
+    assert (needed.library_url(foo) ==
+            'http://example.com/something/fanstatic/foo')
 
 def test_library_url_version_hashing(tmpdir):
     foo = Library('foo', tmpdir.strpath)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.