Changeset 130

Show
Ignore:
Timestamp:
04/03/2007 23:48:46 (20 months ago)
Author:
why
Message:
  • lib/hpricot/parse.rb: XML tags and attribs are no longer downcased.
  • lib/hpricot/elements.rb: expression "//text" matches tag named "text" rather than text nodes. use "//text()" for text nodes.
Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/hpricot/elements.rb

    r123 r130  
    223223                nodes, = Elements.filter(nodes, m[2], false) 
    224224            else 
    225                 meth = "filter[#{m[0]}#{m[1]}]" 
    226                 if Traverse.method_defined? meth 
     225                meth = "filter[#{m[0]}#{m[1]}]" unless m[0].empty? 
     226                if meth and Traverse.method_defined? meth 
    227227                    args = m[2..-1] 
    228228                else 
  • trunk/lib/hpricot/inspect.rb

    r100 r130  
    6161        q.text @name 
    6262 
    63         if @attributes 
    64           @attributes.each {|n, t| 
     63        if @raw_attributes 
     64          @raw_attributes.each {|n, t| 
    6565            q.breakable 
    66             q.text "#{n}=\"#{t}\"" 
     66            q.text "#{n}=\"#{Hpricot.uxs(t)}\"" 
    6767          } 
    6868        end 
  • trunk/lib/hpricot/parse.rb

    r123 r130  
    2929      raise ArgumentError, "An Hpricot document must be built from an input source (a String) or a block." 
    3030    end 
     31 
     32    trans = opts[:xml] ? :to_s : :downcase 
    3133 
    3234    fragment = 
     
    4951      Hpricot.scan(input) do |token| 
    5052        if stack.last[5] == :CDATA and ![:procins, :comment, :cdata].include?(token[0]) and 
    51             !(token[0] == :etag and token[1].downcase == stack.last[0]) 
     53            !(token[0] == :etag and token[1].send(trans) == stack.last[0]) 
    5254          token[0] = :text 
    5355          token[1] = token[3] if token[3] 
     
    6062          end 
    6163 
    62           stagname = token[0] = token[1].downcase 
     64          stagname = token[0] = token[1].send(trans) 
    6365          if ElementContent[stagname] == :EMPTY and !opts[:xml] 
    6466            token[0] = :emptytag 
     
    105107              end 
    106108            end 
     109            unless opts[:xml] 
     110              case token[2] when Hash 
     111                token[2] = token[2].inject({}) { |hsh,(k,v)| hsh[k.downcase] = v; hsh } 
     112              end 
     113            end 
    107114            stack << [stagname, token, [], excluded_tags, included_tags, uncontainable_tags] 
    108115          end 
    109116        when :etag 
    110           etagname = token[0] = token[1].downcase 
     117          etagname = token[0] = token[1].send(trans) 
    111118          if opts[:xhtml_strict] and not ElementContent.has_key? etagname 
    112119            etagname = token[0] = "div" 
  • trunk/lib/hpricot/tag.rb

    r127 r130  
    9393  class STag < BaseEle 
    9494    def initialize(name, attributes=nil) 
    95       @name = name.to_s.downcase 
    96       @raw_attributes = {} 
    97       if attributes 
    98         @raw_attributes = attributes.inject({}) { |hsh,(k,v)| hsh[k.to_s.downcase] = v; hsh } 
    99       end 
     95      @name = name.to_s 
     96      @raw_attributes = attributes || {} 
    10097    end 
    10198    alterable :name, :raw_attributes 
  • trunk/test/test_xml.rb

    r114 r130  
    1414  end 
    1515 
    16   def test_tag_case 
     16  # make sure XML doesn't get downcased 
     17  def test_casing 
    1718    doc = Hpricot::XML(TestFiles::WHY) 
    18     # Hpricot currently downcase-s everything, so this test would fail: 
     19    assert_equal "hourly", (doc.at "sy:updatePeriod").inner_html 
     20    assert_equal 1, (doc/"guid[@isPermaLink]").length 
     21  end 
    1922 
    20     # assert_equal "hourly", (doc.at "sy:updatePeriod").inner_html 
     23  # be sure tags named "text" are ok 
     24  def test_text_tags 
     25    doc = Hpricot::XML("<feed><title>City Poisoned</title><text>Rita Lee has poisoned Brazil.</text></feed>") 
     26    assert_equal "City Poisoned", (doc/"title").text 
    2127  end 
    2228end