Skip to content

Handle HTML links with encoded URIs correctly in svg text labels #2239 #2471

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

Merged
merged 1 commit into from
Mar 13, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lib/svg_text_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,10 @@ function buildSVGText(containerNode, str) {
var dummyAnchor = document.createElement('a');
dummyAnchor.href = href;
if(PROTOCOLS.indexOf(dummyAnchor.protocol) !== -1) {
nodeSpec.href = encodeURI(href);
// Decode href to allow both already encoded and not encoded
// URIs. Without decoding prior encoding, an already encoded
// URI would be encoded twice producing a semantically different URI.
nodeSpec.href = encodeURI(decodeURI(href));
nodeSpec.target = getQuotedMatch(extra, TARGETMATCH) || '_blank';
nodeSpec.popup = getQuotedMatch(extra, POPUPMATCH);
}
Expand Down
10 changes: 10 additions & 0 deletions test/jasmine/tests/svg_text_utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ describe('svg+text utils', function() {
});
});

it('allows encoded URIs in href', function() {
var node = mockTextSVGElement(
'<a href="https://example.com/?q=date%20%3E=%202018-01-01">click</a>'
);

expect(node.text()).toEqual('click');
assertAnchorAttrs(node);
assertAnchorLink(node, 'https://example.com/?q=date%20%3E=%202018-01-01');
});

it('accepts `target` with links and tries to translate it to `xlink:show`', function() {
var specs = [
{target: '_blank', show: 'new'},
Expand Down