ruby / rexml

REXML is an XML toolkit for Ruby
BSD 2-Clause "Simplified" License
133 stars 61 forks source link

Behaviour change from 3.3.1 to 3.3.2 for nested XML handling #181

Closed MahtraDR closed 1 month ago

MahtraDR commented 1 month ago

We have a little project for a scripting engine for an ancient (although still active!) MUD.

This MUD engine has long sent weird "XML" and we've been fine with that for years now. We had a user report that the upgrade from 3.3.1 and 3.3.2 broke our engine. Upon checking, it looks like there was some behaviour change.

This is a sample of the XML we handle which 3.3.1 and prior work perfectly with:

"<a exist=\"-10949883\" noun=\"Jespin\">He</a> is wearing a <a exist=\"76182094\" noun=\"jacket\">soft black suede jacket</a> with fitted sleeves, a <a exist=\"76182143\" noun=\"cufflinks\">pair of iron and onyx cufflinks</a>, a <a exist=\"76182144\" noun=\"pin\">small golden Paupers pin</a>, a <a exist=\"76182145\" noun=\"satchel\">finely tooled grey leather satchel</a>, a pumpkin-stitched bright <a exist=\"76182149\" noun=\"backpack\">orange backpack</a>, a <a exist=\"76182153\" noun=\"shirt\">pale white spidersilk shirt</a>, a <a exist=\"76182154\" noun=\"apron\">leather crafter's apron</a>, an <a exist=\"76182155\" noun=\"breastplate\">etched vultite metal breastplate</a>, a <a exist=\"76182156\" noun=\"gauntlets\">pair of thick leather gauntlets</a> with polished eonake studs, a <a exist=\"76182157\" noun=\"sack\">large black sack</a>, a <a exist=\"76182158\" noun=\"pouch\">deep indigo eel skin pouch</a>, a <a exist=\"76182196\" noun=\"forging-hammer\">perfect steel-handled mithril forging-hammer</a>, a <a exist=\"76182197\" noun=\"pants\">pair of crisp black linen pants</a>, <a exist=\"76182198\" noun=\"greaves\">some thick spiked ora leg greaves</a>, a <a exist=\"76182199\" noun=\"boots\">pair of thick eonake-toed leather boots</a>, and an <a exist=\"76182200\" noun=\"greatshield\">oval silver steel greatshield</a> lined with crimson plates.\r\n"
MahtraDR commented 1 month ago

This is probably related/similar to https://github.com/ruby/rexml/issues/180

kou commented 1 month ago

Does the sample XML is represented as a Ruby string? Or is the content as-is (like the following) the sample XML?

<a exist="-10949883" noun="Jespin">He</a> is wearing a <a exist="76182094" noun="jacket">soft black suede jacket</a> with fitted sleeves, a <a exist="76182143" noun="cufflinks">pair of iron and onyx cufflinks</a>, a <a exist="76182144" noun="pin">small golden Paupers pin</a>, a <a exist="76182145" noun="satchel">finely tooled grey leather satchel</a>, a pumpkin-stitched bright <a exist="76182149" noun="backpack">orange backpack</a>, a <a exist="76182153" noun="shirt">pale white spidersilk shirt</a>, a <a exist="76182154" noun="apron">leather crafter's apron</a>, an <a exist="76182155" noun="breastplate">etched vultite metal breastplate</a>, a <a exist="76182156" noun="gauntlets">pair of thick leather gauntlets</a> with polished eonake studs, a <a exist="76182157" noun="sack">large black sack</a>, a <a exist="76182158" noun="pouch">deep indigo eel skin pouch</a>, a <a exist="76182196" noun="forging-hammer">perfect steel-handled mithril forging-hammer</a>, a <a exist="76182197" noun="pants">pair of crisp black linen pants</a>, <a exist="76182198" noun="greaves">some thick spiked ora leg greaves</a>, a <a exist="76182199" noun="boots">pair of thick eonake-toed leather boots</a>, and an <a exist="76182200" noun="greatshield">oval silver steel greatshield</a> lined with crimson plates.
kou commented 1 month ago

Anyway, it's not a valid XML.

How about surrounding with a dummy root element something like:

<root><a exist="-10949883" noun="Jespin">He</a> is wearing a...</root>

and ignore the dummy root element?

BTW, could you share the related code in the scripting engine?

MahtraDR commented 1 month ago

Anyway, it's not a valid XML.

How about surrounding with a dummy root element something like:

<root><a exist="-10949883" noun="Jespin">He</a> is wearing a...</root>

and ignore the dummy root element?

Yes, I think we could do that, and we have other places where we edit the pseudo-XML the game passes us to make it less uncompliant... It was a big shock change of behaviour here though. If it's as simple as adding dummy <root> tags, we can do that easily, and not worry again.

BTW, could you share the related code in the scripting engine?

Don't judge us! :)

https://github.com/elanthia-online/lich-5/blob/605f6c6e20246ee8a9792b65ba9e24ff06b5b80c/lib/games.rb#L256

kou commented 1 month ago

Yes, I think we could do that, and we have other places where we edit the pseudo-XML the game passes us to make it less uncompliant... It was a big shock change of behaviour here though. If it's as simple as adding dummy <root> tags, we can do that easily, and not worry again.

OK. Could you try it?

BTW, could you share the related code in the scripting engine?

Don't judge us! :)

https://github.com/elanthia-online/lich-5/blob/605f6c6e20246ee8a9792b65ba9e24ff06b5b80c/lib/games.rb#L256

Thanks. It seems that we can do it by "<root>#{$_SERVERSTRING_}</root>" and changing XMLData.

MahtraDR commented 1 month ago

Thanks. It seems that we can do it by "<root>#{$_SERVERSTRING_}</root>" and changingXMLData`.

Thanks for this. It looks good in testing.

Can you think of any drawbacks to this? We're trying to think of any potential problems this might introduce and can't think of any.

kou commented 1 month ago

I don't have any concern for the approach.

MahtraDR commented 1 month ago

Closing this out. The <root> tag fix seems good for us.

I appreciate your help!