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

Should Node#native_content= be a public method? Discuss. #768

Closed
flavorjones opened this issue Sep 26, 2012 · 10 comments
Closed

Should Node#native_content= be a public method? Discuss. #768

flavorjones opened this issue Sep 26, 2012 · 10 comments

Comments

@flavorjones
Copy link
Member

Coming from nokogiri-talk thread here and the related SO question here.

Some operations, such as creating a script tag within a conditional-comment node, are difficult with the current API, since the string argument is escaped before insertion into the DOM.

This sort of thing would be made easier if #native_content= was public and a supported API call.

I don't see any downside. Discuss, please!

@yokolet
Copy link
Member

yokolet commented Oct 4, 2012

I talked with someone with this before. That person needed native_content= method to be public.

I agree with @flavorjones .

@tenderlove
Copy link
Member

Then let's do it!

@senthilnayagam
Copy link

I tried using the private method, still my html comment got escaped

node.send(:native_content=,node.content + "")

@flavorjones
Copy link
Member Author

@senthilnayagam Depending on what your node type is, the "<" and ">" characters may not be valid in that node. Most nodes' text cannot contain these characters unescaped, and so libxml2 is doing the right thing in escaping them.

If you reread the nokogiri-talk thread, you'll see this issues specifically mentions comment nodes, in which those characters are valid:

#! /usr/bin/env ruby

require 'nokogiri'
comment = Nokogiri.XML('<r><!-- foo --></r>').at('//comment()')

comment.content = " < "
puts comment.to_xml
#=> <!-- &lt; -->

comment.send :native_content=, " <" 
puts comment.to_xml
#=> <!-- < -->

@yokolet
Copy link
Member

yokolet commented Oct 5, 2012

Is there any complete test case that I can confirm the change does the right thing?

@flavorjones
Copy link
Member Author

@yokolet - I'll take care of it. :)

flavorjones added a commit that referenced this issue Oct 5, 2012
@flavorjones
Copy link
Member Author

@yokolet - branch issue-768 contains a failing test for JRuby. I tried to make the obvious change to XmlNode.java but got sucking into NullPointerExceptions ... best to leave Java to the experts. ;) Can you take a look?

@yokolet
Copy link
Member

yokolet commented Oct 5, 2012

@flavorjones Thanks. I'll try issue-768 branch. BTW, I fixed NPE by rev. 3255717 . Maybe the branch was created after that?

@yokolet
Copy link
Member

yokolet commented Oct 5, 2012

Reply to myself. Yes, nokogiri network shows the issue-768 branch was created before my change.

flavorjones added a commit that referenced this issue Oct 5, 2012
@yokolet
Copy link
Member

yokolet commented Oct 5, 2012

I confirmed the test passed on JRuby as well. So, I merged issue-768 branch to master and pushed.

I'm going to close this issue.

@yokolet yokolet closed this as completed Oct 5, 2012
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

4 participants