Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behaviour using replace #308

Closed
ileitch opened this issue Jul 15, 2010 · 4 comments
Closed

Strange behaviour using replace #308

ileitch opened this issue Jul 15, 2010 · 4 comments

Comments

@ileitch
Copy link

ileitch commented Jul 15, 2010

Trying to replace a Text node with a Fragment (or anything else for that matter) results in some odd behaviour.

html = %q{blah http://google.com blah blah}
new_html = %q{blah <a href="http://google.com">http://google.com</a> blah blah}
frag = Nokogiri::HTML.fragment(html)
text = frag.children.first
p frag.to_html
text.replace(Nokogiri::HTML.fragment(new_html))
p "-" * 10
p frag.to_html

output:

"blah http://google.com blah blah"
"----------"
"<a href=\"http://google.com\">http://google.com</a>"

The "blah"s at the start and end are now missing.

ruby 1.8.6 (2009-06-08 patchlevel 369) [i686-darwin10.2.0]
nokogiri (1.4.2)
Snow Leopard 10.6.4

@flavorjones
Copy link
Member

Reproduced. Will take a look.

@ileitch
Copy link
Author

ileitch commented Aug 25, 2010

Hi, just tested this with 1.4.3.1 in 1.8.7 and 1.9.2 and the problem still exists.

I've tried using various approaches without success to work around this bug as I'd love to replace Hpricot with Nokogiri. Can you think of any way to work around this?

Cheers

@flavorjones
Copy link
Member

XML::Node#{replace,add_previous_sibling,add_next_sibling} edge cases fixed related to libxml's text node merging. closed by 7540988

@flavorjones
Copy link
Member

this is fixed in the branches '1.4' and 'master', and is targetted for 1.4.4.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants