Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 03950d8

Browse filesBrowse files
authored
Merge pull request plotly#2471 from plotly/allow-encoded-uris-in-svg-text
Handle HTML links with encoded URIs correctly in svg text labels plotly#2239
2 parents cea4fd4 + e40c795 commit 03950d8
Copy full SHA for 03950d8

File tree

Expand file treeCollapse file tree

2 files changed

+14
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-1
lines changed

‎src/lib/svg_text_utils.js

Copy file name to clipboardExpand all lines: src/lib/svg_text_utils.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,10 @@ function buildSVGText(containerNode, str) {
469469
var dummyAnchor = document.createElement('a');
470470
dummyAnchor.href = href;
471471
if(PROTOCOLS.indexOf(dummyAnchor.protocol) !== -1) {
472-
nodeSpec.href = encodeURI(href);
472+
// Decode href to allow both already encoded and not encoded
473+
// URIs. Without decoding prior encoding, an already encoded
474+
// URI would be encoded twice producing a semantically different URI.
475+
nodeSpec.href = encodeURI(decodeURI(href));
473476
nodeSpec.target = getQuotedMatch(extra, TARGETMATCH) || '_blank';
474477
nodeSpec.popup = getQuotedMatch(extra, POPUPMATCH);
475478
}

‎test/jasmine/tests/svg_text_utils_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/svg_text_utils_test.js
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ describe('svg+text utils', function() {
173173
});
174174
});
175175

176+
it('allows encoded URIs in href', function() {
177+
var node = mockTextSVGElement(
178+
'<a href="https://example.com/?q=date%20%3E=%202018-01-01">click</a>'
179+
);
180+
181+
expect(node.text()).toEqual('click');
182+
assertAnchorAttrs(node);
183+
assertAnchorLink(node, 'https://example.com/?q=date%20%3E=%202018-01-01');
184+
});
185+
176186
it('accepts `target` with links and tries to translate it to `xlink:show`', function() {
177187
var specs = [
178188
{target: '_blank', show: 'new'},

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.