Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed to not apply absolute prefix for relative urls starting with '#'. #3

Merged
merged 2 commits into from

3 participants

@datakurre
Collaborator

Currently, diazo appends absolute prefix also for relative urls starting with "#". It prevents designers from linking local anchors in theme, when absolute prefix is defined.

This patch would define a wrapper around urlparse.urljoin, which calls urljoin only when the given url doesn't start with '#'.

Test included. All tests for diazo and plone.app.theming seem to pass.

See: http://stackoverflow.com/questions/10098846/how-to-avoid-that-diazo-change-links-in-plone

@optilude
Owner

Thanks for this!

Could we call the function something other than urljoin? It's a bit confusing since that name is commonly understood from the standard library.

Martin

@datakurre
Collaborator

Thanks. The patch should be much cleaner now. -Asko

@lrowe lrowe merged commit fe7cfe7 into plone:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  docs/HISTORY.txt
@@ -1,6 +1,9 @@
History
=======
+* Fixed to not apply absolute prefix for relative urls starting with '#'.
+ [datakurre]
+
0.3 - 2010-05-29
----------------
View
9 lib/diazo/rules.py
@@ -31,6 +31,13 @@
apply_rules = pkg_xsl('apply-rules.xsl')
fixup_themes = pkg_xsl('fixup-themes.xsl')
+def anchor_safe_urljoin(base, url):
+ """Join the base with the url only when the url doesn't start with '#'"""
+ if url.startswith('#'):
+ return url
+ else:
+ return urljoin(base, url)
+
def add_identifiers(rules_doc):
"""Add identifiers to the rules for debugging"""
for i, elem in enumerate(rules_doc.xpath(
@@ -103,7 +110,7 @@ def apply_absolute_prefix(theme_doc, absolute_prefix):
url = urljoin(absolute_prefix, node.get('src'))
node.set('src', url)
for node in theme_doc.xpath('//*[@href]'):
- url = urljoin(absolute_prefix, node.get('href'))
+ url = anchor_safe_urljoin(absolute_prefix, node.get('href'))
node.set('href', url)
for node in theme_doc.xpath('//style'):
node.text = IMPORT_STYLESHEET.sub(
View
1  lib/diazo/tests/absolute-prefix/output.html
@@ -34,5 +34,6 @@
<input type="submit" src="/foo.jpg" />
<input type="submit" src="http://site.com/foo.jpg" />
<a href="/abs/foo.html">Link</a>
+ <a href="#foo">Anchor</a>
</body>
</html>
View
1  lib/diazo/tests/absolute-prefix/theme.html
@@ -34,5 +34,6 @@
<input type="submit" src="/foo.jpg" />
<input type="submit" src="http://site.com/foo.jpg" />
<a href="foo.html">Link</a>
+ <a href="#foo">Anchor</a>
</body>
</html>
Something went wrong with that request. Please try again.