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

quick-xml v0.27+ changed behaviour when writing empty values #617

Closed
decathorpe opened this issue Jun 22, 2023 · 7 comments · Fixed by #620
Closed

quick-xml v0.27+ changed behaviour when writing empty values #617

decathorpe opened this issue Jun 22, 2023 · 7 comments · Fixed by #620
Labels
enhancement help wanted serde Issues related to mapping from Rust types to XML

Comments

@decathorpe
Copy link

decathorpe commented Jun 22, 2023

I'm using quick-xml for my XML-RPC crate (dxr) and I've been a happy user so far, thank you for maintaining the crate!

I'm trying to update my quick-xml dependency to a newer version (dxr is currently stuck at v0.25), but I'm hitting a roadblock. It looks like the new serde serializer that was implemented for v0.27 changed some behaviour when writing empty values.

For example, it now writes self-closing XML tags - previously, I got <value><string></string></value> for an empty string value, but with quick-xml v0.27+, I get <value><string/></value>. While this is technically valid XML, my library cannot write self-closing tags like this in order to maintain compatibility with other XML-RPC implementations (some older ones don't accept self-closing XML tags).

Is there a way to get back the old behaviour (i.e. deserialize an empty $value to <foo></foo> instead of <foo/>?

@dralley
Copy link
Collaborator

dralley commented Jun 22, 2023

It doesn't look configurable, currently. I'm sure it could be, though, if that is useful / necessary functionality.

https://github.com/tafia/quick-xml/blob/master/src/se/element.rs#L68-L75

@Mingun
Copy link
Collaborator

Mingun commented Jun 23, 2023

Yes, I'm happy to accept a PR which makes this configurable. I suggest Serializer::expand_empty_elements(enable: bool), like the same-named option for a parser, false by default

@Mingun Mingun added enhancement help wanted serde Issues related to mapping from Rust types to XML labels Jun 23, 2023
@decathorpe
Copy link
Author

I can try to work on this. But how would that integrate? I'm currently just doing quick_xml::se::to_string(&value), and I don't want to have to write a custom serializer implementation.

@Mingun
Copy link
Collaborator

Mingun commented Jun 23, 2023

You will need to instantiate Serializer manually unstead of using helper function. To find the right place for tests you can first add necessary changes without the setting and see what tests are failed in serde-se, then implement setting and add new tests nearby to failed ones.

@bahlo
Copy link
Contributor

bahlo commented Jun 27, 2023

@Mingun Do you think a feature flag would work for this as well instead of a serializer option?

@decathorpe Did you start with this already? I can take a stab unless you want to ✌🏻

@decathorpe
Copy link
Author

I haven't had the time to look into it yet, so if you want to take a stab at it, that would be great 👍🏻

@Mingun
Copy link
Collaborator

Mingun commented Jun 27, 2023

@bahlo, because cargo features is additive, having this as a feature option could break somebody who will (transitively) depend on two crates with different requirements. I think, that usual setting will be enough. I believe that disabling producing of self-closed tags is a niche feature, so shortcut function is not necessary (but you could write one in your own crate).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants