Skip to content

Commit

Permalink
Merge pull request #2471 from plotly/allow-encoded-uris-in-svg-text
Browse files Browse the repository at this point in the history
Handle HTML links with encoded URIs correctly in svg text labels #2239
  • Loading branch information
rmoestl authored Mar 13, 2018
2 parents cea4fd4 + e40c795 commit 03950d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit 03950d8

Please sign in to comment.