@@ -268,7 +268,11 @@ def inspect
268268 # u = Text.new( "sean russell", false, nil, true )
269269 # u.value #-> "sean russell"
270270 def value
271- @unnormalized ||= Text ::unnormalize ( @string , doctype )
271+ if document . nil?
272+ @unnormalized ||= Text ::unnormalize ( @string , doctype )
273+ else
274+ @unnormalized ||= Text ::unnormalize ( @string , doctype , entity_expansion_text_limit : document . entity_expansion_text_limit )
275+ end
272276 end
273277
274278 # Sets the contents of this text node. This expects the text to be
@@ -411,11 +415,11 @@ def Text::normalize( input, doctype=nil, entity_filter=nil )
411415 end
412416
413417 # Unescapes all possible entities
414- def Text ::unnormalize ( string , doctype = nil , filter = nil , illegal = nil )
418+ def Text ::unnormalize ( string , doctype = nil , filter = nil , illegal = nil , entity_expansion_text_limit : Security . entity_expansion_text_limit )
415419 sum = 0
416420 string . gsub ( /\r \n ?/ , "\n " ) . gsub ( REFERENCE ) {
417421 s = Text . expand ( $&, doctype , filter )
418- if sum + s . bytesize > Security . entity_expansion_text_limit
422+ if sum + s . bytesize > entity_expansion_text_limit
419423 raise "entity expansion has grown too large"
420424 else
421425 sum += s . bytesize
0 commit comments