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

Bug encountered: slashes ("/") in attribute strings may cause issues with deserialization #246

Open
carphi opened this issue Oct 16, 2024 · 1 comment

Comments

@carphi
Copy link

carphi commented Oct 16, 2024

(First of all, thank you for your awesome library!!!)
I have the following class property in a class svg which i want to serialize:

@XmlSerialName("xmlns") val xmlns: String = "http://www.w3.org/2000/svg"

It serializes correctly to <svg xmlns="http://www.w3.org/2000/svg">...</svg>

However, when I want to deserialize the string again, i get this error:

nl.adaptivity.xmlutil.XmlException: Local name "{http://www.w3.org/2000/svg}svg" for root tag does not match expected name "svg"

I guess this is because the deserialzer looks for all occurences of '/svg' as the closing tag, because 'svg' is also my opening tag. However, '/svg' also occures in my attribute string.

@carphi carphi changed the title Bug encountered: slashes ("/") in tag attributes may cause issues in deserialization Bug encountered: slashes ("/") in attribute strings may cause issues in deserialization Oct 16, 2024
@carphi carphi changed the title Bug encountered: slashes ("/") in attribute strings may cause issues in deserialization Bug encountered: slashes ("/") in attribute strings may cause issues with deserialization Oct 16, 2024
@pdvrieze
Copy link
Owner

pdvrieze commented Oct 17, 2024

You are confused with how namespace attributes are managed. They are not valid attributes (I've added a check to pedantic mode to disable xml and xmlns both as name and prefix). Adding an attribute called xmlns will not put SVG in the correct namespace, thus the svg tag when parsing does not match the namespace expected ("" or null) as it now has a namespace in the string.

What you want to do is to use:

@XmlSerialName("svg", "http://www.w3.org/2000/svg", "")
class Svg() { /* content */ }

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