Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Apr 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/HISTORY.txt
@@ -1,6 +1,9 @@
History History
======= =======


* Fixed to not apply absolute prefix for relative urls starting with '#'.
[datakurre]

0.3 - 2010-05-29 0.3 - 2010-05-29
---------------- ----------------


Expand Down
9 changes: 8 additions & 1 deletion lib/diazo/rules.py
Expand Up @@ -31,6 +31,13 @@
apply_rules = pkg_xsl('apply-rules.xsl') apply_rules = pkg_xsl('apply-rules.xsl')
fixup_themes = pkg_xsl('fixup-themes.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): def add_identifiers(rules_doc):
"""Add identifiers to the rules for debugging""" """Add identifiers to the rules for debugging"""
for i, elem in enumerate(rules_doc.xpath( for i, elem in enumerate(rules_doc.xpath(
Expand Down Expand Up @@ -103,7 +110,7 @@ def apply_absolute_prefix(theme_doc, absolute_prefix):
url = urljoin(absolute_prefix, node.get('src')) url = urljoin(absolute_prefix, node.get('src'))
node.set('src', url) node.set('src', url)
for node in theme_doc.xpath('//*[@href]'): 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) node.set('href', url)
for node in theme_doc.xpath('//style'): for node in theme_doc.xpath('//style'):
node.text = IMPORT_STYLESHEET.sub( node.text = IMPORT_STYLESHEET.sub(
Expand Down
1 change: 1 addition & 0 deletions lib/diazo/tests/absolute-prefix/output.html
Expand Up @@ -34,5 +34,6 @@
<input type="submit" src="/foo.jpg" /> <input type="submit" src="/foo.jpg" />
<input type="submit" src="http://site.com/foo.jpg" /> <input type="submit" src="http://site.com/foo.jpg" />
<a href="/abs/foo.html">Link</a> <a href="/abs/foo.html">Link</a>
<a href="#foo">Anchor</a>
</body> </body>
</html> </html>
1 change: 1 addition & 0 deletions lib/diazo/tests/absolute-prefix/theme.html
Expand Up @@ -34,5 +34,6 @@
<input type="submit" src="/foo.jpg" /> <input type="submit" src="/foo.jpg" />
<input type="submit" src="http://site.com/foo.jpg" /> <input type="submit" src="http://site.com/foo.jpg" />
<a href="foo.html">Link</a> <a href="foo.html">Link</a>
<a href="#foo">Anchor</a>
</body> </body>
</html> </html>