@@ -8,6 +8,16 @@ describe('svg+text utils', function() {
88
99 describe ( 'convertToTspans' , function ( ) {
1010
11+ var stringFromCodePoint ;
12+
13+ beforeAll ( function ( ) {
14+ stringFromCodePoint = String . fromCodePoint ;
15+ } ) ;
16+
17+ afterEach ( function ( ) {
18+ String . fromCodePoint = stringFromCodePoint ;
19+ } ) ;
20+
1121 function mockTextSVGElement ( txt ) {
1222 return d3 . select ( 'body' )
1323 . append ( 'svg' )
@@ -330,6 +340,28 @@ describe('svg+text utils', function() {
330340 expect ( i ) . toBe ( 355 ) ;
331341 } ) ;
332342
343+ it ( 'decodes arbitrary decimal and hex number entities (IE case)' , function ( ) {
344+ // IE does not have String.fromCodePoint
345+ String . fromCodePoint = undefined ;
346+ expect ( String . fromCodePoint ) . toBeUndefined ( ) ;
347+
348+ var i = 0 ;
349+ for ( var n = 33 ; n < 0x10FFFF ; n = Math . round ( n * 1.03 ) ) {
350+ var node = mockTextSVGElement (
351+ '&#x' + n . toString ( 16 ) +
352+ '; = &#' + n . toString ( ) +
353+ '; = &#x' + n . toString ( 16 ) . toUpperCase ( ) + ';'
354+ ) ;
355+ var char = stringFromCodePoint ( n ) ;
356+ expect ( node . text ( ) ) . toBe ( char + ' = ' + char + ' = ' + char , n ) ;
357+ i ++ ;
358+ }
359+ // not really necessary to assert this, but we tested 355 characters,
360+ // weighted toward the low end but continuing all the way to the
361+ // end of the unicode definition
362+ expect ( i ) . toBe ( 355 ) ;
363+ } ) ;
364+
333365 it ( 'does not decode entities prematurely' , function ( ) {
334366 var testCases = [
335367 '<b>not bold</b>' ,
0 commit comments