Skip to content

Commit

Permalink
Merge pull request #4050 from plone/issue-4049
Browse files Browse the repository at this point in the history
Fix relative URI resources
  • Loading branch information
petschki authored Nov 11, 2024
2 parents ba15fc5 + b3bc44f commit 26c659a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Products/CMFPlone/resources/browser/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class ResourceBase:
initialization.
"""

@staticmethod
def is_external_url(resource):
# we check if the resource string starts with http and //
# according to relative URI definition in
# https://www.ietf.org/rfc/rfc3986.txt chapter 4.2
return resource.startswith("http") or resource.startswith("//")

def _request_bundles(self):
request = self.request
request_enabled_bundles = set(getattr(request, "enabled_bundles", []))
Expand Down Expand Up @@ -138,7 +145,7 @@ def check_dependencies(bundle_name, depends, bundles):
depends = check_dependencies(name, record.depends, js_names)
if depends == "__broken__":
continue
external = record.jscompilation.startswith("http")
external = self.is_external_url(record.jscompilation)
PloneScriptResource(
context=self.context,
name=name,
Expand All @@ -160,7 +167,7 @@ def check_dependencies(bundle_name, depends, bundles):
depends = check_dependencies(name, record.depends, css_names)
if depends == "__broken__":
continue
external = record.csscompilation.startswith("http")
external = self.is_external_url(record.csscompilation)
PloneStyleResource(
context=self.context,
name=name,
Expand All @@ -187,7 +194,7 @@ def check_dependencies(bundle_name, depends, bundles):
# add Theme JS
if themedata["production_js"]:
# we ignore development_js for external detection
external = themedata["production_js"].startswith("http")
external = self.is_external_url(themedata["production_js"])
PloneScriptResource(
context=self.context,
name="theme",
Expand All @@ -210,7 +217,7 @@ def check_dependencies(bundle_name, depends, bundles):
# add Theme CSS
if themedata["production_css"]:
# we ignore development_css for external detection
external = themedata["production_css"].startswith("http")
external = self.is_external_url(themedata["production_css"])
PloneStyleResource(
context=self.context,
name="theme",
Expand Down
9 changes: 9 additions & 0 deletions Products/CMFPlone/tests/testResourceRegistries.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ def test_resource_bogus(self):
resource.file_data, b'I_do_not_exist',
)

def test_relative_uri_resource(self):
bundle = self._make_test_bundle()
bundle.jscompilation = "//foo.bar/foobar.js"
view = ScriptsView(self.app, self.app.REQUEST, None, None)
view.update()
results = view.render()
self.assertIn('src="//foo.bar/foobar.js"', results)


class TestStylesViewlet(PloneTestCase.PloneTestCase):
def test_styles_viewlet(self):
styles = StylesView(self.layer["portal"], self.layer["request"], None)
Expand Down
2 changes: 2 additions & 0 deletions news/4049.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix resources with relative URI in registry.
[petschki]

0 comments on commit 26c659a

Please sign in to comment.