MCPcopy Index your code
hub / github.com/plotly/plotly.js / assertAnchorAttrs

Function assertAnchorAttrs

test/jasmine/tests/svg_text_utils_test.js:47–73  ·  view source on GitHub ↗
(node, expectedAttrs, msg)

Source from the content-addressed store, hash-verified

45 }
46
47 function assertAnchorAttrs(node, expectedAttrs, msg) {
48 var a = node.select('a');
49
50 if(!expectedAttrs) expectedAttrs = {};
51
52 var WHITE_LIST = ['xlink:href', 'xlink:show', 'style', 'target', 'onclick'];
53 var attrs = listAttributes(a.node());
54
55 // check that no other attribute are found in anchor,
56 // which can be lead to XSS attacks.
57
58 var wrongAttrs = [];
59 attrs.forEach(function(attr) {
60 if(WHITE_LIST.indexOf(attr) === -1) wrongAttrs.push(attr);
61 });
62
63 expect(wrongAttrs).toEqual([], msg);
64
65 var style = expectedAttrs.style || '';
66 var fullStyle = style || '';
67 if(style) fullStyle += ';';
68 fullStyle += 'cursor:pointer';
69
70 expect(a.attr('style')).toBe(fullStyle, msg);
71
72 expect(a.attr('onclick')).toBe(expectedAttrs.onclick || null, msg);
73 }
74
75 function listAttributes(node) {
76 var items = Array.prototype.slice.call(node.attributes);

Callers 1

Calls 1

listAttributesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…