Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 195505 | Differences between
and this patch

Collapse All | Expand All

(-)lib/rexml/parsers/baseparser.rb (-9 / +47 lines)
Lines 1-5 Link Here
1
require 'rexml/parseexception'
1
require 'rexml/parseexception'
2
require 'rexml/source'
2
require 'rexml/source'
3
require 'set'
3
4
4
module REXML
5
module REXML
5
  module Parsers
6
  module Parsers
Lines 24-30 Link Here
24
    # Nat Price gave me some good ideas for the API.
25
    # Nat Price gave me some good ideas for the API.
25
    class BaseParser
26
    class BaseParser
26
      NCNAME_STR= '[\w:][\-\w\d.]*'
27
      NCNAME_STR= '[\w:][\-\w\d.]*'
27
      NAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
28
      NAME_STR= "(?:(#{NCNAME_STR}):)?(#{NCNAME_STR})"
29
      UNAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
28
30
29
      NAMECHAR = '[\-\w\d\.:]'
31
      NAMECHAR = '[\-\w\d\.:]'
30
      NAME = "([\\w:]#{NAMECHAR}*)"
32
      NAME = "([\\w:]#{NAMECHAR}*)"
Lines 35-41 Link Here
35
37
36
      DOCTYPE_START = /\A\s*<!DOCTYPE\s/um
38
      DOCTYPE_START = /\A\s*<!DOCTYPE\s/um
37
      DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
39
      DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
38
      ATTRIBUTE_PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um
40
      ATTRIBUTE_PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\4/um
39
      COMMENT_START = /\A<!--/u
41
      COMMENT_START = /\A<!--/u
40
      COMMENT_PATTERN = /<!--(.*?)-->/um
42
      COMMENT_PATTERN = /<!--(.*?)-->/um
41
      CDATA_START = /\A<!\[CDATA\[/u
43
      CDATA_START = /\A<!\[CDATA\[/u
Lines 45-51 Link Here
45
      XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>/um
47
      XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>/um
46
      INSTRUCTION_START = /\A<\?/u
48
      INSTRUCTION_START = /\A<\?/u
47
      INSTRUCTION_PATTERN = /<\?(.*?)(\s+.*?)?\?>/um
49
      INSTRUCTION_PATTERN = /<\?(.*?)(\s+.*?)?\?>/um
48
      TAG_MATCH = /^<((?>#{NAME_STR}))\s*((?>\s+#{NAME_STR}\s*=\s*(["']).*?\3)*)\s*(\/)?>/um
50
      TAG_MATCH = /^<((?>#{NAME_STR}))\s*((?>\s+#{UNAME_STR}\s*=\s*(["']).*?\5)*)\s*(\/)?>/um
49
      CLOSE_MATCH = /^\s*<\/(#{NAME_STR})\s*>/um
51
      CLOSE_MATCH = /^\s*<\/(#{NAME_STR})\s*>/um
50
52
51
      VERSION = /\bversion\s*=\s*["'](.*?)['"]/um
53
      VERSION = /\bversion\s*=\s*["'](.*?)['"]/um
Lines 133-138 Link Here
133
        @tags = []
135
        @tags = []
134
        @stack = []
136
        @stack = []
135
        @entities = []
137
        @entities = []
138
        @nsstack = []
136
      end
139
      end
137
140
138
      def position
141
      def position
Lines 213-218 Link Here
213
            return [ :processing_instruction, *@source.match(INSTRUCTION_PATTERN, true)[1,2] ]
216
            return [ :processing_instruction, *@source.match(INSTRUCTION_PATTERN, true)[1,2] ]
214
          when DOCTYPE_START
217
          when DOCTYPE_START
215
            md = @source.match( DOCTYPE_PATTERN, true )
218
            md = @source.match( DOCTYPE_PATTERN, true )
219
            @nsstack.unshift(curr_ns=Set.new)
216
            identity = md[1]
220
            identity = md[1]
217
            close = md[2]
221
            close = md[2]
218
            identity =~ IDENTITY
222
            identity =~ IDENTITY
Lines 288-293 Link Here
288
                val = attdef[3]
292
                val = attdef[3]
289
                val = attdef[4] if val == "#FIXED "
293
                val = attdef[4] if val == "#FIXED "
290
                pairs[attdef[0]] = val
294
                pairs[attdef[0]] = val
295
                if attdef[0] =~ /^xmlns:(.*)/
296
                  @nsstack[0] << $1
297
                end
291
              end
298
              end
292
            end
299
            end
293
            return [ :attlistdecl, element, pairs, contents ]
300
            return [ :attlistdecl, element, pairs, contents ]
Lines 312-317 Link Here
312
        begin
319
        begin
313
          if @source.buffer[0] == ?<
320
          if @source.buffer[0] == ?<
314
            if @source.buffer[1] == ?/
321
            if @source.buffer[1] == ?/
322
              @nsstack.shift
315
              last_tag = @tags.pop
323
              last_tag = @tags.pop
316
              #md = @source.match_to_consume( '>', CLOSE_MATCH)
324
              #md = @source.match_to_consume( '>', CLOSE_MATCH)
317
              md = @source.match( CLOSE_MATCH, true )
325
              md = @source.match( CLOSE_MATCH, true )
Lines 345-363 Link Here
345
                raise REXML::ParseException.new("missing attribute quote", @source) if @source.match(MISSING_ATTRIBUTE_QUOTES )
353
                raise REXML::ParseException.new("missing attribute quote", @source) if @source.match(MISSING_ATTRIBUTE_QUOTES )
346
                raise REXML::ParseException.new("malformed XML: missing tag start", @source) 
354
                raise REXML::ParseException.new("malformed XML: missing tag start", @source) 
347
              end
355
              end
348
              attrs = []
356
              attributes = {}
349
              if md[2].size > 0
357
              prefixes = Set.new
350
                attrs = md[2].scan( ATTRIBUTE_PATTERN )
358
              prefixes << md[2] if md[2]
359
              @nsstack.unshift(curr_ns=Set.new)
360
              if md[4].size > 0
361
                attrs = md[4].scan( ATTRIBUTE_PATTERN )
351
                raise REXML::ParseException.new( "error parsing attributes: [#{attrs.join ', '}], excess = \"#$'\"", @source) if $' and $'.strip.size > 0
362
                raise REXML::ParseException.new( "error parsing attributes: [#{attrs.join ', '}], excess = \"#$'\"", @source) if $' and $'.strip.size > 0
363
                attrs.each { |a,b,c,d,e| 
364
                  if b == "xmlns"
365
                    if c == "xml"
366
                      if d != "http://www.w3.org/XML/1998/namespace"
367
                        msg = "The 'xml' prefix must not be bound to any other namespace "+
368
                        "(http://www.w3.org/TR/REC-xml-names/#ns-decl)"
369
                        raise REXML::ParseException.new( msg, @source, self )
370
                      end
371
                    elsif c == "xmlns"
372
                      msg = "The 'xmlns' prefix must not be declared "+
373
                      "(http://www.w3.org/TR/REC-xml-names/#ns-decl)"
374
                      raise REXML::ParseException.new( msg, @source, self)
375
                    end
376
                    curr_ns << c
377
                  elsif b
378
                    prefixes << b unless b == "xml"
379
                  end
380
                  attributes[a] = e 
381
                }
352
              end
382
              end
353
        
383
        
354
              if md[4]
384
              # Verify that all of the prefixes have been defined
385
              for prefix in prefixes
386
                unless @nsstack.find{|k| k.member?(prefix)}
387
                  raise UndefinedNamespaceException.new(prefix,@source,self)
388
                end
389
              end
390
391
              if md[6]
355
                @closed = md[1]
392
                @closed = md[1]
393
                @nsstack.shift
356
              else
394
              else
357
                @tags.push( md[1] )
395
                @tags.push( md[1] )
358
              end
396
              end
359
              attributes = {}
360
              attrs.each { |a,b,c| attributes[a] = c }
361
              return [ :start_element, md[1], attributes ]
397
              return [ :start_element, md[1], attributes ]
362
            end
398
            end
363
          else
399
          else
Lines 371-376 Link Here
371
            # return PullEvent.new( :text, md[1], unnormalized )
407
            # return PullEvent.new( :text, md[1], unnormalized )
372
            return [ :text, md[1] ]
408
            return [ :text, md[1] ]
373
          end
409
          end
410
        rescue REXML::UndefinedNamespaceException
411
          raise
374
        rescue REXML::ParseException
412
        rescue REXML::ParseException
375
          raise
413
          raise
376
        rescue Exception, NameError => error
414
        rescue Exception, NameError => error
(-)lib/rexml/parsers/treeparser.rb (-2 / +3 lines)
Lines 29-36 Link Here
29
              return
29
              return
30
            when :start_element
30
            when :start_element
31
              tag_stack.push(event[1])
31
              tag_stack.push(event[1])
32
              # find the observers for namespaces
32
              el = @build_context = @build_context.add_element( event[1], event[2] )
33
              @build_context = @build_context.add_element( event[1], event[2] )
34
            when :end_element
33
            when :end_element
35
              tag_stack.pop
34
              tag_stack.pop
36
              @build_context = @build_context.parent
35
              @build_context = @build_context.parent
Lines 86-91 Link Here
86
          end
85
          end
87
        rescue REXML::Validation::ValidationException
86
        rescue REXML::Validation::ValidationException
88
          raise
87
          raise
88
        rescue REXML::UndefinedNamespaceException
89
          raise
89
        rescue
90
        rescue
90
          raise ParseException.new( $!.message, @parser.source, @parser, $! )
91
          raise ParseException.new( $!.message, @parser.source, @parser, $! )
91
        end
92
        end
(-)lib/rexml/document.rb (-1 / +2 lines)
Lines 66-71 Link Here
66
		def add( child )
66
		def add( child )
67
			if child.kind_of? XMLDecl
67
			if child.kind_of? XMLDecl
68
				@children.unshift child
68
				@children.unshift child
69
        child.parent = self
69
			elsif child.kind_of? DocType
70
			elsif child.kind_of? DocType
70
        # Find first Element or DocType node and insert the decl right 
71
        # Find first Element or DocType node and insert the decl right 
71
        # before it.  If there is no such node, just insert the child at the
72
        # before it.  If there is no such node, just insert the child at the
Lines 183-189 Link Here
183
        output = Output.new( output, xml_decl.encoding )
184
        output = Output.new( output, xml_decl.encoding )
184
      end
185
      end
185
      formatter = if indent > -1
186
      formatter = if indent > -1
186
          if transitive
187
          if trans
187
            REXML::Formatters::Transitive.new( indent, ie_hack )
188
            REXML::Formatters::Transitive.new( indent, ie_hack )
188
          else
189
          else
189
            REXML::Formatters::Pretty.new( indent, ie_hack )
190
            REXML::Formatters::Pretty.new( indent, ie_hack )
(-)lib/rexml/element.rb (-5 / +6 lines)
Lines 553-558 Link Here
553
    def attribute( name, namespace=nil )
553
    def attribute( name, namespace=nil )
554
      prefix = nil
554
      prefix = nil
555
      prefix = namespaces.index(namespace) if namespace
555
      prefix = namespaces.index(namespace) if namespace
556
      prefix = nil if prefix == 'xmlns'
556
      attributes.get_attribute( "#{prefix ? prefix + ':' : ''}#{name}" )
557
      attributes.get_attribute( "#{prefix ? prefix + ':' : ''}#{name}" )
557
    end
558
    end
558
559
Lines 854-868 Link Here
854
    #   Source (see Element.initialize).  If not supplied or nil, a
855
    #   Source (see Element.initialize).  If not supplied or nil, a
855
    #   new, default Element will be constructed
856
    #   new, default Element will be constructed
856
    # Returns:: the added Element
857
    # Returns:: the added Element
857
    #  a = Element.new 'a'
858
    #  a = Element.new('a')
858
    #  a.elements.add Element.new 'b'  #-> <a><b/></a>
859
    #  a.elements.add(Element.new('b'))  #-> <a><b/></a>
859
    #  a.elements.add 'c'              #-> <a><b/><c/></a>
860
    #  a.elements.add('c')               #-> <a><b/><c/></a>
860
    def add element=nil
861
    def add element=nil
861
      rv = nil
862
      rv = nil
862
      if element.nil?
863
      if element.nil?
863
        Element.new "", self, @element.context
864
        Element.new("", self, @element.context)
864
      elsif not element.kind_of?(Element)
865
      elsif not element.kind_of?(Element)
865
        Element.new element, self, @element.context
866
        Element.new(element, self, @element.context)
866
      else
867
      else
867
        @element << element
868
        @element << element
868
        element.context = @element.context
869
        element.context = @element.context
(-)lib/rexml/undefinednamespaceexception.rb (+8 lines)
Line 0 Link Here
1
require 'rexml/parseexception'
2
module REXML
3
  class UndefinedNamespaceException < ParseException
4
    def initialize( prefix, source, parser )
5
      super( "Undefined prefix #{prefix} found" )
6
    end
7
  end
8
end
(-)lib/rexml/source.rb (-2 / +2 lines)
Lines 17-24 Link Here
17
      elsif arg.kind_of? Source
17
      elsif arg.kind_of? Source
18
        arg
18
        arg
19
      else
19
      else
20
        raise "#{source.class} is not a valid input stream.  It must walk \n"+
20
        raise "#{arg.class} is not a valid input stream.  It must walk \n"+
21
        "like either a String, IO, or Source."
21
          "like either a String, an IO, or a Source."
22
      end
22
      end
23
    end
23
    end
24
  end
24
  end
(-)lib/rexml/attribute.rb (-1 / +1 lines)
Lines 50-56 Link Here
50
					@element = first.element
50
					@element = first.element
51
				end
51
				end
52
			elsif first.kind_of? String
52
			elsif first.kind_of? String
53
				@element = parent if parent.kind_of? Element
53
				@element = parent
54
				self.name = first
54
				self.name = first
55
				@normalized = second.to_s
55
				@normalized = second.to_s
56
			else
56
			else
(-)lib/rexml/rexml.rb (-6 / +8 lines)
Lines 1-3 Link Here
1
# -*- encoding: utf-8 -*-
1
# REXML is an XML toolkit for Ruby[http://www.ruby-lang.org], in Ruby.
2
# REXML is an XML toolkit for Ruby[http://www.ruby-lang.org], in Ruby.
2
#
3
#
3
# REXML is a _pure_ Ruby, XML 1.0 conforming,
4
# REXML is a _pure_ Ruby, XML 1.0 conforming,
Lines 10-17 Link Here
10
#
11
#
11
# Main page:: http://www.germane-software.com/software/rexml
12
# Main page:: http://www.germane-software.com/software/rexml
12
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
13
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
13
# Version:: 3.1.7.1
14
# Version:: 3.1.7.2
14
# Date:: 2007/209
15
# Date:: 2007/275
16
# Revision:: $Revision$
15
# 
17
# 
16
# This API documentation can be downloaded from the REXML home page, or can
18
# This API documentation can be downloaded from the REXML home page, or can
17
# be accessed online[http://www.germane-software.com/software/rexml_doc]
19
# be accessed online[http://www.germane-software.com/software/rexml_doc]
Lines 20-29 Link Here
20
# or can be accessed 
22
# or can be accessed 
21
# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
23
# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
22
module REXML
24
module REXML
23
  COPYRIGHT = "Copyright © 2001-2007 Sean Russell <ser@germane-software.com>"
25
  COPYRIGHT = "Copyright \xC2\xA9 2001-2006 Sean Russell <ser@germane-software.com>"
24
  DATE = "2007/209"
26
  VERSION = "3.1.7.2"
25
  VERSION = "3.1.7.1"
27
  DATE = "2007/275"
26
  REVISION = "$Revision: 1270$".gsub(/\$Revision:|\$/,'').strip
28
  REVISION = "$Revision$".gsub(/\$Revision:|\$/,'').strip
27
29
28
  Copyright = COPYRIGHT
30
  Copyright = COPYRIGHT
29
  Version = VERSION
31
  Version = VERSION
30
  + 3a3bbbf4-582e-0410-a78b-8bf2211dae1f:/local/ruby-trunk/dtd/dtd.rb:1298
32
  + 3a3bbbf4-582e-0410-a78b-8bf2211dae1f:/local/ruby-trunk/dtd/dtd.rb:1298
31
  - 3a3bbbf4-582e-0410-a78b-8bf2211dae1f:/local/rexml-trunk/src/rexml:1287
33
  - 3a3bbbf4-582e-0410-a78b-8bf2211dae1f:/local/rexml-trunk/src/rexml:1287
Line 4 Link Here
Line 4 Link Here
4
  + 3a3bbbf4-582e-0410-a78b-8bf2211dae1f:/local/rexml-trunk/src/rexml:1287
3
  + 3a3bbbf4-582e-0410-a78b-8bf2211dae1f:/local/rexml-trunk/src/rexml:1287
Line 4 Link Here
Line 4 Link Here
Line 4 Link Here

Return to bug 195505