ruby-changes:28760
From: shyouhei <ko1@a...>
Date: Sat, 18 May 2013 23:55:27 +0900 (JST)
Subject: [ruby-changes:28760] shyouhei:r40812 (ruby_1_8_7): merge revision(s) 39384,39509,39511: [Backport #7961]
shyouhei 2013-05-18 23:55:14 +0900 (Sat, 18 May 2013) New Revision: 40812 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40812 Log: merge revision(s) 39384,39509,39511: [Backport #7961] * lib/rexml/document.rb (REXML::Document.entity_expansion_text_limit): new attribute to read/write entity expansion text limit. the default limit is 10Kb. * lib/rexml/text.rb (REXML::Text.unnormalize): check above attribute. * lib/rexml/document.rb: move entity_expansion_limit accessor to ... * lib/rexml/rexml.rb: ... here to make rexml/text independent from REXML::Document. It causes circular require. * lib/rexml/document.rb (REXML::Document.entity_expansion_limit): deprecated. * lib/rexml/document.rb (REXML::Document.entity_expansion_limit=): deprecated. * lib/rexml/text.rb: add missing require "rexml/rexml" for REXML.entity_expansion_limit. Reported by Robert Ulejczyk. Thanks!!! [ruby-core:52895] [Bug #7961] * lib/rexml/document.rb: move entity_expansion_text_limit accessor to ... * lib/rexml/document.rb (REXML::Document.entity_expansion_text_limit): * lib/rexml/document.rb (REXML::Document.entity_expansion_text_limit=): REXML.entity_expansion_text_limit. Modified directories: branches/ruby_1_8_7/ Modified files: branches/ruby_1_8_7/ChangeLog branches/ruby_1_8_7/lib/rexml/document.rb branches/ruby_1_8_7/lib/rexml/rexml.rb branches/ruby_1_8_7/lib/rexml/text.rb branches/ruby_1_8_7/version.h Index: ruby_1_8_7/ChangeLog =================================================================== --- ruby_1_8_7/ChangeLog (revision 40811) +++ ruby_1_8_7/ChangeLog (revision 40812) @@ -1,3 +1,24 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_8_7/ChangeLog#L1 +Sat May 18 23:34:50 2013 Kouhei Sutou <kou@c...> + + * lib/rexml/document.rb: move entity_expansion_text_limit accessor to ... + * lib/rexml/rexml.rb: ... here to make rexml/text independent from + REXML::Document. It causes circular require. + * lib/rexml/document.rb (REXML::Document.entity_expansion_text_limit): + deprecated. + * lib/rexml/document.rb (REXML::Document.entity_expansion_text_limit=): + deprecated. + * lib/rexml/text.rb: add missing require "rexml/rexml" for + REXML.entity_expansion_text_limit. + Reported by Robert Ulejczyk. Thanks!!! [ruby-core:52895] [Bug #7961] + +Sat May 18 23:34:50 2013 Aaron Patterson <aaron@t...> + + * lib/rexml/document.rb (REXML::Document.entity_expansion_text_limit): + new attribute to read/write entity expansion text limit. the default + limit is 10Kb. + + * lib/rexml/text.rb (REXML::Text.unnormalize): check above attribute. + Fri Oct 12 12:25:15 2012 URABE Shyouhei <shyouhei@r...> * error.c (name_err_to_s): we need not infect msg. Index: ruby_1_8_7/version.h =================================================================== --- ruby_1_8_7/version.h (revision 40811) +++ ruby_1_8_7/version.h (revision 40812) @@ -1,15 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_8_7/version.h#L1 #define RUBY_VERSION "1.8.7" -#define RUBY_RELEASE_DATE "2012-10-12" +#define RUBY_RELEASE_DATE "2013-05-18" #define RUBY_VERSION_CODE 187 -#define RUBY_RELEASE_CODE 20121012 -#define RUBY_PATCHLEVEL 371 +#define RUBY_RELEASE_CODE 20130518 +#define RUBY_PATCHLEVEL 372 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 8 #define RUBY_VERSION_TEENY 7 -#define RUBY_RELEASE_YEAR 2012 -#define RUBY_RELEASE_MONTH 10 -#define RUBY_RELEASE_DAY 12 +#define RUBY_RELEASE_YEAR 2013 +#define RUBY_RELEASE_MONTH 5 +#define RUBY_RELEASE_DAY 18 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; Index: ruby_1_8_7/lib/rexml/document.rb =================================================================== --- ruby_1_8_7/lib/rexml/document.rb (revision 40811) +++ ruby_1_8_7/lib/rexml/document.rb (revision 40812) @@ -213,6 +213,20 @@ module REXML https://github.com/ruby/ruby/blob/trunk/ruby_1_8_7/lib/rexml/document.rb#L213 return @@entity_expansion_limit end + # Set the entity expansion limit. By default the limit is set to 10240. + # + # Deprecated. Use REXML.entity_expansion_text_limit= instead. + def Document::entity_expansion_text_limit=( val ) + REXML.entity_expansion_text_limit = val + end + + # Get the entity expansion limit. By default the limit is set to 10000. + # + # Deprecated. Use REXML.entity_expansion_text_limit instead. + def Document::entity_expansion_text_limit + return REXML.entity_expansion_text_limit + end + attr_reader :entity_expansion_count def record_entity_expansion Index: ruby_1_8_7/lib/rexml/text.rb =================================================================== --- ruby_1_8_7/lib/rexml/text.rb (revision 40811) +++ ruby_1_8_7/lib/rexml/text.rb (revision 40812) @@ -1,3 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_8_7/lib/rexml/text.rb#L1 +require 'rexml/rexml' require 'rexml/entity' require 'rexml/doctype' require 'rexml/child' @@ -308,37 +309,35 @@ module REXML https://github.com/ruby/ruby/blob/trunk/ruby_1_8_7/lib/rexml/text.rb#L309 # Unescapes all possible entities def Text::unnormalize( string, doctype=nil, filter=nil, illegal=nil ) - rv = string.clone - rv.gsub!( /\r\n?/, "\n" ) - matches = rv.scan( REFERENCE ) - return rv if matches.size == 0 - rv.gsub!( NUMERICENTITY ) {|m| - m=$1 - m = "0#{m}" if m[0] == ?x - [Integer(m)].pack('U*') + sum = 0 + string.gsub( /\r\n?/, "\n" ).gsub( REFERENCE ) { + s = Text.expand($&, doctype, filter) + if sum + s.bytesize > REXML.entity_expansion_text_limit + raise "entity expansion has grown too large" + else + sum += s.bytesize + end + s } - matches.collect!{|x|x[0]}.compact! - if matches.size > 0 - if doctype - matches.each do |entity_reference| - unless filter and filter.include?(entity_reference) - entity_value = doctype.entity( entity_reference ) - re = /&#{entity_reference};/ - rv.gsub!( re, entity_value ) if entity_value - end - end + end + + def Text.expand(ref, doctype, filter) + if ref[1] == ?# + if ref[2] == ?x + [ref[3...-1].to_i(16)].pack('U*') else - matches.each do |entity_reference| - unless filter and filter.include?(entity_reference) - entity_value = DocType::DEFAULT_ENTITIES[ entity_reference ] - re = /&#{entity_reference};/ - rv.gsub!( re, entity_value.value ) if entity_value - end - end + [ref[2...-1].to_i].pack('U*') end - rv.gsub!( /&/, '&' ) + elsif ref == '&' + '&' + elsif filter and filter.include?( ref[1...-1] ) + ref + elsif doctype + doctype.entity( ref[1...-1] ) or ref + else + entity_value = DocType::DEFAULT_ENTITIES[ ref[1...-1] ] + entity_value ? entity_value.value : ref end - rv end end end Index: ruby_1_8_7/lib/rexml/rexml.rb =================================================================== --- ruby_1_8_7/lib/rexml/rexml.rb (revision 40811) +++ ruby_1_8_7/lib/rexml/rexml.rb (revision 40812) @@ -29,4 +29,16 @@ module REXML https://github.com/ruby/ruby/blob/trunk/ruby_1_8_7/lib/rexml/rexml.rb#L29 Copyright = COPYRIGHT Version = VERSION + + @@entity_expansion_text_limit = 10_240 + + # Set the entity expansion limit. By default the limit is set to 10240. + def self.entity_expansion_text_limit=( val ) + @@entity_expansion_text_limit = val + end + + # Get the entity expansion limit. By default the limit is set to 10240. + def self.entity_expansion_text_limit + return @@entity_expansion_text_limit + end end Property changes on: ruby_1_8_7 ___________________________________________________________________ Added: svn:mergeinfo Merged /trunk:r39384,39509,39511 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/