From 2403ad9e7de8976a83798f9d86f82f3b5ae0d2cd Mon Sep 17 00:00:00 2001 From: ser Date: Sun, 15 Jun 2003 18:31:16 +0000 Subject: REXML hadn't been tested with Ruby 1.8.0, which was really, really, unbelievably stupid of me. There were a lot of warnings and some errors that were caused by Block vs. Proc differences; these have been fixed. REXML passes all of the tests under Ruby 1.8.0. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rexml/parsers/baseparser.rb | 23 +++++++++++++---------- lib/rexml/parsers/sax2parser.rb | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'lib/rexml/parsers') diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb index 614bdc3948..cfcea16f1d 100644 --- a/lib/rexml/parsers/baseparser.rb +++ b/lib/rexml/parsers/baseparser.rb @@ -23,14 +23,15 @@ module REXML # # Nat Price gave me some good ideas for the API. class BaseParser - NCNAME_STR= '[\w:][-\w\d.]*' + NCNAME_STR= '[\w:][\-\w\d.]*' NAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}" - NAMECHAR = '[-\w\d\.:]' + NAMECHAR = '[\-\w\d\.:]' NAME = "([\\w:]#{NAMECHAR}*)" NMTOKEN = "(?:#{NAMECHAR})+" NMTOKENS = "#{NMTOKEN}(\\s+#{NMTOKEN})*" REFERENCE = "(?:&#{NAME};|&#\\d+;|&#x[0-9a-fA-F]+;)" + REFERENCE_RE = /#{REFERENCE}/ DOCTYPE_START = /\A\s*)/um @@ -38,6 +39,7 @@ module REXML COMMENT_START = /\A/um CDATA_START = /\A/um CDATA_PATTERN = //um XMLDECL_START = /\A<\?xml\s/u; XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um @@ -51,7 +53,7 @@ module REXML STANDALONE = /\bstandalone=["'](.*?)['"]/um ENTITY_START = /^\s*/um ENUMERATION = "\\(\\s*#{NMTOKEN}(?:\\s*\\|\\s*#{NMTOKEN})*\\s*\\)" @@ -61,16 +63,17 @@ module REXML ATTVALUE = "(?:\"((?:[^<&\"]|#{REFERENCE})*)\")|(?:'((?:[^<&']|#{REFERENCE})*)')" DEFAULTDECL = "(#REQUIRED|#IMPLIED|(?:(#FIXED\\s+)?#{ATTVALUE}))" ATTDEF = "\\s+#{NAME}\\s+#{ATTTYPE}\\s+#{DEFAULTDECL}" + ATTDEF_RE = /#{ATTDEF}/ ATTLISTDECL_START = /^\s*/um NOTATIONDECL_START = /^\s*/um - SYSTEM = /^\s*/um + PUBLIC = /^\s*/um + SYSTEM = /^\s*/um TEXT_PATTERN = /\A([^<]*)/um # Entity constants - PUBIDCHAR = "\x20\x0D\x0Aa-zA-Z0-9-()+,./:=?;!*@$_%#" + PUBIDCHAR = "\x20\x0D\x0Aa-zA-Z0-9\\-()+,./:=?;!*@$_%#" SYSTEMLITERAL = %Q{((?:"[^"]*")|(?:'[^']*'))} PUBIDLITERAL = %Q{("[#{PUBIDCHAR}']*"|'[#{PUBIDCHAR}]*')} EXTERNALID = "(?:(?:(SYSTEM)\\s+#{SYSTEMLITERAL})|(?:(PUBLIC)\\s+#{PUBIDLITERAL}\\s+#{SYSTEMLITERAL}))" @@ -243,7 +246,7 @@ module REXML contents = md[0] pairs = {} - values = md[0].scan( ATTDEF ) + values = md[0].scan( ATTDEF_RE ) values.each do |attdef| unless attdef[3] == "#IMPLIED" attdef.compact! @@ -263,9 +266,9 @@ module REXML raise REXML::ParseException.new( "error parsing notation: no matching pattern", @source ) end return [ :notationdecl, md[1], md[2], md[3] ] - when /^\s*\]\s*>/um + when CDATA_END @document_status = :after_doctype - @source.match( /^\s*\]\s*>/um, true ) + @source.match( CDATA_END, true ) return [ :end_doctype ] end end @@ -358,7 +361,7 @@ module REXML def unnormalize( string, entities=nil, filter=nil ) rv = string.clone rv.gsub!( /\r\n?/, "\n" ) - matches = rv.scan( REFERENCE) + matches = rv.scan( REFERENCE_RE ) return rv if matches.size == 0 rv.gsub!( /�*((?:\d+)|(?:x[a-fA-F0-9]+));/ ) {|m| m=$1 diff --git a/lib/rexml/parsers/sax2parser.rb b/lib/rexml/parsers/sax2parser.rb index 8598fd43e9..4cddc4806d 100644 --- a/lib/rexml/parsers/sax2parser.rb +++ b/lib/rexml/parsers/sax2parser.rb @@ -185,7 +185,7 @@ module REXML end def add( pair ) - if pair[-1].kind_of? Proc + if pair[-1].kind_of? Proc or (defined? Block and pair[-1].kind_of? Block) @procs << pair unless @procs.include? pair else @listeners << pair unless @listeners.include? pair -- cgit v1.2.3