remove_attribute gives exception

421 views
Skip to first unread message

Bill Harding

unread,
Nov 16, 2010, 5:05:34 PM11/16/10
to nokogiri-talk
Feeling like a bit of a newb not being able to figure this one out
(and well, I guess I am a bit of a newb on Nokogiri) but here goes:

I have an Nokogiri::XML::Node that has attributes, one of which I'm
trying to remove.

I am trying to use the following code to do so:

node.attributes["background"].remove

It actually works on a few of my servers, but it does not work on my
64bit Ubuntu Lynx install. I've tried it with various versions of
Nokogiri, including 1.4.4.

Looking over the difference between my local install and the servers
that work, it appears that, on the servers,

node.attributes returns a hash, whereas on my install, node.attributes
returns a Nokogiri::XML::Element. Here's some representative HTML of
what I'm trying to parse:

<table><tr><td background="java\0script:alert('XSS')>;"></td></tr></
table>

Anyone have an idea what might cause node.attributes to not return a
hash? I notice that in NodeExtensions there is an #attributes method
that returns self. It seems that that is the behavior I'm observing.
But I don't know why my node would be defaulting to that method rather
than the method defined by Nokogiri::XML::Node.

Bill Harding

unread,
Nov 17, 2010, 2:40:21 PM11/17/10
to nokogiri-talk
Alright, just took a second look and figured out the answer. My local
machine had the roxml gem installed, which overrides
Nokogiri::XML::Element's #attributes method. Removing the gem re-
enables our ability to remove of elements.
Reply all
Reply to author
Forward
0 new messages