Changeset 160

Show
Ignore:
Timestamp:
02/21/2008 13:36:48 (5 months ago)
Author:
why
Message:
  • lib/hpricot/elements.rb: a more liberal xpath attr parsing from ticket #115. thanks, wrs!
Location:
trunk
Files:
3 modified

Legend:

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

    r156 r160  
    9191      childs = [] 
    9292      attrs = args.grep(Hash) 
    93       childs.concat((args - attrs).map do |x| 
     93      childs.concat((args - attrs).flatten.map do |x| 
    9494        if x.respond_to? :to_html 
    9595          Hpricot.make(x.to_html) 
  • trunk/lib/hpricot/elements.rb

    r155 r160  
    262262    end 
    263263 
    264     ATTR_RE = %r!\[ *(?:(@)([\w\(\)-]+)|([\w\(\)-]+\(\))) *([~\!\|\*$\^=]*) *'?"?([^\]'"]*)'?"? *\]!i 
     264    ATTR_RE = %r!\[ *(?:(@)([\w\(\)-]+)|([\w\(\)-]+\(\))) *([~\!\|\*$\^=]*) *'?"?([^'"]*)'?"? *\]!i 
    265265    BRACK_RE = %r!(\[) *([^\]]*) *\]+!i 
    266266    FUNC_RE = %r!(:)?([a-zA-Z0-9\*_-]*)\( *[\"']?([^ \)]*?)['\"]? *\)! 
  • trunk/test/test_paths.rb

    r83 r160  
    1414    end 
    1515  end 
     16  def test_attr_brackets 
     17    doc = Hpricot('<input name="vendor[porkpies]"/>') 
     18    assert_equal 1, (doc/'input[@name^="vendor[porkpies]"]').length 
     19    assert_equal 1, (doc/'input[@name="vendor[porkpies]"]').length 
     20    assert_equal 0, (doc/'input[@name$="]]]]]"]').length 
     21 
     22    doc = Hpricot('<input name="vendor[porkpies][meaty]"/>') 
     23    assert_equal 1, (doc/'input[@name^="vendor[porkpies][meaty]"]').length 
     24  end 
    1625end