Skip to content

Commit

Permalink
Merge pull request #63 from huubbouma/master
Browse files Browse the repository at this point in the history
use anchor_safe_urljoin for xlink:href attributes
  • Loading branch information
lrowe authored Oct 11, 2016
2 parents 58d27ef + 2e2fcaa commit 5dbf906
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ New features:

- *add item here*

- only add absolute prefix for xlink:href attributes if url doesn't start
with a '#' (use anchor_safe_urljoin)
[huubbouma]

Bug fixes:

- *add item here*
Expand Down
2 changes: 1 addition & 1 deletion lib/diazo/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def apply_absolute_prefix(theme_doc, absolute_prefix):
node.set('src', url)
for xlink_attr in theme_doc.xpath('//@*[local-name()="xlink:href"]'):
node = xlink_attr.getparent()
url = urljoin(absolute_prefix, node.get('xlink:href'))
url = anchor_safe_urljoin(absolute_prefix, node.get('xlink:href'))
node.set('xlink:href', url)
for node in theme_doc.xpath('//*[@srcset]'):
srcset = node.get('srcset')
Expand Down
9 changes: 9 additions & 0 deletions lib/diazo/tests/absolute-prefix/output.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@
<input type="submit" src="http://site.com/foo.jpg" />
<a href="/abs/foo.html">Link</a>
<a href="#foo">Anchor</a>
<svg>
<symbol id="symbol666">
<circle cx="20" cy="20" r="20" stroke-width="5" stroke="red" fill="red">
</circle>
</symbol>
</svg>
<div xmlns:xlink="http://www.w3.org/1999/xlink">
<svg><use xlink:href="/abs/img/foo.svg"></use></svg>
<span xlink:href="/abs/foo.html"></span>
<svg>
<use xlink:href="#symbol666" x="0" y="0" width="100" height="50"></use>
</svg>
</div>
</body>
</html>
9 changes: 9 additions & 0 deletions lib/diazo/tests/absolute-prefix/theme.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@
<input type="submit" src="http://site.com/foo.jpg" />
<a href="foo.html">Link</a>
<a href="#foo">Anchor</a>
<svg>
<symbol id="symbol666">
<circle cx="20" cy="20" r="20" stroke-width="5" stroke="red" fill="red">
</circle>
</symbol>
</svg>
<div xmlns:xlink="http://www.w3.org/1999/xlink">
<svg><use xlink:href="img/foo.svg"></use></svg>
<span xlink:href="foo.html"></span>
<svg>
<use xlink:href="#symbol666" x="0" y="0" width="100" height="50"></use>
</svg>
</div>
</body>
</html>

0 comments on commit 5dbf906

Please sign in to comment.