@@ -25,6 +25,11 @@ describe('svg+text utils', function() {
2525            expect ( a . attr ( 'xlink:show' ) ) . toBe ( href  ===  null  ? null  : 'new' ) ; 
2626        } 
2727
28+         function  assertTspanStyle ( node ,  style )  { 
29+             var  tspan  =  node . select ( 'tspan' ) ; 
30+             expect ( tspan . attr ( 'style' ) ) . toBe ( style ) ; 
31+         } 
32+ 
2833        function  assertAnchorAttrs ( node )  { 
2934            var  a  =  node . select ( 'a' ) ; 
3035
@@ -75,6 +80,16 @@ describe('svg+text utils', function() {
7580            assertAnchorLink ( node ,  null ) ; 
7681        } ) ; 
7782
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+ 
7893        it ( 'whitelist http hrefs' ,  function ( )  { 
7994            var  node  =  mockTextSVGElement ( 
8095                '<a href="http://bl.ocks.org/">bl.ocks.org</a>' 
@@ -134,5 +149,50 @@ describe('svg+text utils', function() {
134149                assertAnchorLink ( node ,  'https://abc.com/myFeature.jsp?name=abc&pwd=def' ) ; 
135150            } ) ; 
136151        } ) ; 
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+         } ) ; 
137197    } ) ; 
138198} ) ; 
0 commit comments