@@ -25,6 +25,11 @@ describe('svg+text utils', function() {
25
25
expect ( a . attr ( 'xlink:show' ) ) . toBe ( href === null ? null : 'new' ) ;
26
26
}
27
27
28
+ function assertTspanStyle ( node , style ) {
29
+ var tspan = node . select ( 'tspan' ) ;
30
+ expect ( tspan . attr ( 'style' ) ) . toBe ( style ) ;
31
+ }
32
+
28
33
function assertAnchorAttrs ( node ) {
29
34
var a = node . select ( 'a' ) ;
30
35
@@ -75,6 +80,16 @@ describe('svg+text utils', function() {
75
80
assertAnchorLink ( node , null ) ;
76
81
} ) ;
77
82
83
+ it ( 'whitelist relative hrefs (interpreted as http)' , function ( ) {
84
+ var node = mockTextSVGElement (
85
+ '<a href="/mylink">mylink</a>'
86
+ ) ;
87
+
88
+ expect ( node . text ( ) ) . toEqual ( 'mylink' ) ;
89
+ assertAnchorAttrs ( node ) ;
90
+ assertAnchorLink ( node , '/mylink' ) ;
91
+ } ) ;
92
+
78
93
it ( 'whitelist http hrefs' , function ( ) {
79
94
var node = mockTextSVGElement (
80
95
'<a href="http://bl.ocks.org/">bl.ocks.org</a>'
@@ -134,5 +149,50 @@ describe('svg+text utils', function() {
134
149
assertAnchorLink ( node , 'https://abc.com/myFeature.jsp?name=abc&pwd=def' ) ;
135
150
} ) ;
136
151
} ) ;
152
+
153
+ it ( 'allow basic spans' , function ( ) {
154
+ var node = mockTextSVGElement (
155
+ '<span>text</span>'
156
+ ) ;
157
+
158
+ expect ( node . text ( ) ) . toEqual ( 'text' ) ;
159
+ assertTspanStyle ( node , null ) ;
160
+ } ) ;
161
+
162
+ it ( 'ignore unquoted styles in spans' , function ( ) {
163
+ var node = mockTextSVGElement (
164
+ '<span style=unquoted>text</span>'
165
+ ) ;
166
+
167
+ expect ( node . text ( ) ) . toEqual ( 'text' ) ;
168
+ assertTspanStyle ( node , null ) ;
169
+ } ) ;
170
+
171
+ it ( 'allow quoted styles in spans' , function ( ) {
172
+ var node = mockTextSVGElement (
173
+ '<span style="quoted: yeah;">text</span>'
174
+ ) ;
175
+
176
+ expect ( node . text ( ) ) . toEqual ( 'text' ) ;
177
+ assertTspanStyle ( node , 'quoted: yeah;' ) ;
178
+ } ) ;
179
+
180
+ it ( 'ignore extra stuff after span styles' , function ( ) {
181
+ var node = mockTextSVGElement (
182
+ '<span style="quoted: yeah;"disallowed: indeed;">text</span>'
183
+ ) ;
184
+
185
+ expect ( node . text ( ) ) . toEqual ( 'text' ) ;
186
+ assertTspanStyle ( node , 'quoted: yeah;' ) ;
187
+ } ) ;
188
+
189
+ it ( 'escapes HTML entities in span styles' , function ( ) {
190
+ var node = mockTextSVGElement (
191
+ '<span style="quoted: yeah&\';;">text</span>'
192
+ ) ;
193
+
194
+ expect ( node . text ( ) ) . toEqual ( 'text' ) ;
195
+ assertTspanStyle ( node , 'quoted: yeah&\';;' ) ;
196
+ } ) ;
137
197
} ) ;
138
198
} ) ;
0 commit comments