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

fix namespace prefix deserialize #797

Closed
wants to merge 2 commits into from
Closed

Conversation

KaiserY
Copy link

@KaiserY KaiserY commented Aug 23, 2024

Similar to #539, namespace prefix (e.g. r:id) also map to @r:id instead of @id, possibly fix #591.

@codecov-commenter
Copy link

codecov-commenter commented Aug 23, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.10%. Comparing base (7558577) to head (16653eb).
Report is 94 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #797      +/-   ##
==========================================
- Coverage   61.81%   60.10%   -1.72%     
==========================================
  Files          41       41              
  Lines       16798    16100     -698     
==========================================
- Hits        10384     9677     -707     
- Misses       6414     6423       +9     
Flag Coverage Δ
unittests 60.10% <100.00%> (-1.72%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Mingun Mingun added enhancement serde Issues related to mapping from Rust types to XML namespaces Issues related to namespaces support labels Aug 26, 2024
@Mingun
Copy link
Collaborator

Mingun commented Aug 26, 2024

The problem with that approach that in the real document prefix not necessary will be called r. This is different from the xmlns prefix, which is a special prefix that is always defined, cannot be redefined and its namespace cannot be assigned to another prefix. In other words, all of that are prohibited:

  • xmlns:xmlns="something-not-xmlns-namespace"
  • xmlns:xmlns="http://www.w3.org/2000/xmlns/"
  • xmlns:any-name="http://www.w3.org/2000/xmlns/"

In the end that means that the only way to declare namespace prefix is to use xmlns:prefix-name="namespace". xmlns is constant. That is why we have an exception for it, although you generally should not read namespace prefixes into the fields, because prefix-name can be arbitrary XML identifier and rely on the particular name for it is dangerous.

The right approach is to include namespace name to the #[serde(rename)] and during deserialization resolve actual prefixes into namespaces, compose a field name from them (for example, @attr{namespace}) and pass that name to the type's Visitor. That already was explored in #466 and we should move forward that way.

@KaiserY
Copy link
Author

KaiserY commented Aug 26, 2024

Thanks for the full explanation. in my case i'm parsing ooxml, somehow the prefix seem fixed, so i think this will be a quick fix. I will dig more into #466, close this for now.

@KaiserY KaiserY closed this Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement namespaces Issues related to namespaces support serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

problems with colon separators
3 participants