Changeset 126

Show
Ignore:
Timestamp:
03/29/2007 18:39:54 (20 months ago)
Author:
why
Message:
  • ext/hpricot_scan: working on slash escaping in attributes, for no particular reason.
  • lib/hpricot/text.rb: a relic from HTree, no longer helpful.
  • lib/hpricot/tag.rb: cdata to_s returns raw data, text to_s unescapes.
  • lib/hpricot/builder.rb: escape attributes when building HTML.
  • lib/hpricot/traverse.rb: when getting attributes, unescape.
Location:
trunk
Files:
1 removed
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/hpricot_scan/hpricot_common.rl

    r116 r126  
    1717  NameCap = Name >_tag %tag; 
    1818  NameAttr = NameChar+ >_akey %akey ; 
    19   Q1Attr = [^']* >_aval %aval ; 
    20   Q2Attr = [^"]* >_aval %aval ; 
     19  Q1Char = ( "\\\'" | [^'] ) ; 
     20  Q1Attr = Q1Char* >_aval %aval ; 
     21  Q2Char = ( "\\\"" | [^"] ) ; 
     22  Q2Attr = Q2Char* >_aval %aval ; 
    2123  UnqAttr = ( space >_aval | [^ \t\r\n<>"'] >_aval [^ \t\r\n<>]* %aunq ) ;  
    2224  Nmtoken = NameChar+ >_akey %akey ; 
  • trunk/lib/hpricot/builder.rb

    r125 r126  
    7474      attrs = args.grep(Hash) 
    7575      childs.concat((args - attrs).map { |x| Text.new(Hpricot.xs(x)) }) 
    76       attrs = attrs.inject({}) { |hsh, hsh2| hsh.merge(hsh2) } 
     76      attrs = attrs.inject({}) do |hsh, ath| 
     77        ath.each do |k, v| 
     78          hsh[k] = Hpricot.xs(v) 
     79        end 
     80        hsh 
     81      end 
    7782 
    7883      # create the element itself 
  • trunk/lib/hpricot/tag.rb

    r125 r126  
    147147 
    148148  class CData < Text 
    149     alias_method :inner_text, :content 
     149    alias_method :to_s, :content 
    150150    alias_method :to_plain_text, :content 
    151151    def output(out, opts = {}) 
  • trunk/lib/hpricot/traverse.rb

    r123 r126  
    777777    end 
    778778    def get_attribute(name) 
    779       self.attributes && self.attributes[name.to_s] 
     779      a = self.attributes && self.attributes[name.to_s] 
     780      a = Hpricot.uxs(a) if a 
     781      a 
    780782    end 
    781783    alias_method :[], :get_attribute 
  • trunk/test/test_preserved.rb

    r96 r126  
    4444    assert_roundtrip TestFiles::CY0 
    4545  end 
     46 
     47  def test_escaping_of_attrs 
     48    # ampersands in URLs 
     49    str = %{<a href="http://google.com/search?q=hpricot&amp;l=en">Google</a>} 
     50    doc = Hpricot(str) 
     51    assert_equal "http://google.com/search?q=hpricot&l=en", doc.at(:a)['href'] 
     52    assert_equal str, doc.to_html 
     53  end 
    4654end