Skip to content

Commit

Permalink
fragment method deals with regular expression characters. LH #73
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Mar 25, 2009
1 parent a1833f6 commit 5588dd2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* Bugfixes

* Fixed a problem with nil passed to CDATA constructor
* Fragment method deals with regular expression characters
(Thanks Joel!) LH #73

=== 1.2.3 / 2009-03-22

Expand Down
4 changes: 2 additions & 2 deletions lib/nokogiri/xml/fragment_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize node, original_html
end

def start_element name, attrs = []
@doc_started = true if @original_html =~ /^<#{name}/
@doc_started = true if @original_html.start_with?('<' + name)
return unless @doc_started

node = Node.new(name, @document)
Expand All @@ -21,7 +21,7 @@ def start_element name, attrs = []
end

def characters string
@doc_started = true if @original_html =~ /^\s*#{string}/
@doc_started = true if @original_html.strip.start_with?(string)
@stack.last << Nokogiri::XML::Text.new(string, @document)
end

Expand Down
6 changes: 6 additions & 0 deletions test/html/test_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def test_swap
assert_equal 0, @html.css('div').length
end

def test_swap_with_regex_characters
@html.at('div').swap('<a href="foo">ba)r</a>')
a_tag = @html.css('a').first
assert_equal 'ba)r', a_tag.text
end

def test_attribute_decodes_entities
node = @html.at('div')
node['href'] = 'foo&bar'
Expand Down

0 comments on commit 5588dd2

Please sign in to comment.