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

odd number of arguments #35

Closed
vikasmaskeri opened this issue May 6, 2009 · 8 comments
Closed

odd number of arguments #35

vikasmaskeri opened this issue May 6, 2009 · 8 comments

Comments

@vikasmaskeri
Copy link

There seems to be a problem with parsing if the html tags are irregular.
For example, in an iframe tag, if the 'height' attribute is present but
no value is written for it, then an error occurs saying that "odd number
of arguments for hash".
Please suggest a solution for this problem.

@flavorjones
Copy link
Member

I'm unable to reproduce this. Can you post a gist of an example test case? Also please include the output of

puts Nokogiri::VERSION
puts Nokogiri::LIBXML_PARSER_VERSION

Thank you!

@flavorjones
Copy link
Member

Hi, just checking in. Can you please provide a sample case to reproduce this, along with the version information above? Thanks!

@vikasmaskeri
Copy link
Author

Hi, sorry for the late reply.
Here is a sample case,
<iframe style="width: 0%; height: 0px" src="http://someurl" frameborder=0 scrolling=no
allowtransparency></iframe>
The 'allowtransparency' tag does not have any value. The error shown is
/var/lib/gems/1.8/gems/nokogiri-1.2.3/lib/nokogiri/xml/fragment_handler.rb:17:in []': odd number of arguments for Hash (ArgumentError) from /var/lib/gems/1.8/gems/nokogiri-1.2.3/lib/nokogiri/xml/fragment_handler.rb:17:instart_element'
I am not having this error now because now I dont use 'before' or 'after' methods(where I think the error is) to place the above iframe tag in my html code. Instead I am using the above tag as a string.

@vikasmaskeri
Copy link
Author

PS: Here's the version information
Nokogiri::VERSION 1.2.3
Nokogiri::LIBXML_PARSER_VERSION "20632"

@flavorjones
Copy link
Member

I still don't understand how to reproduce this issue. Can you please gist a test case which demonstrates this behavior? Thanks so much!

@flavorjones
Copy link
Member

Never mind. I've figured it out. http://gist.github.com/109879

@flavorjones
Copy link
Member

fixing FragmentHandler to not blow up if there are attributes without values. closed by 557dc5c.

@flavorjones
Copy link
Member

Please note that this fix only makes Nokogiri not blow up when it encounters attributes without values in before/after/inner_html= calls.

Libxml does not handle attributes without values very well, dropping all attributes declared after the single attribute. To prevent this, you should properly declare your attributes with values, e.g. "allowtransparency=true".

flavorjones pushed a commit that referenced this issue Apr 7, 2021
Build with and without libxml
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