Fix too early handling of namespace declarations - #1002
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1002 +/- ##
==========================================
- Coverage 57.31% 56.13% -1.18%
==========================================
Files 46 47 +1
Lines 18197 18431 +234
==========================================
- Hits 10429 10346 -83
- Misses 7768 8085 +317
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Ok, it seems that now all possible paths are covered |
|
Wait a bit. Found another suspicious test |
Helper will become more complicated in the next commits, so introduce it to keep only one place with such complexness
In next commits `last_peeked()` cannot be used due to starting violating borrow checker rules
…of namespace bindings
failures (8):
serde-de-xsi (6):
as_field::nested_nil::field::nil_on_parent
as_field::nested_nil::field::nil_on_self
as_field::nested_nil::value::nil_on_parent
as_field::nested_nil::value::nil_on_self
top_level_option::nested_nil::string
top_level_option::nested_nil::unit
serde-issues (2):
issue953::open_close
issue953::self_closed
…it must be 0
failures (20, +14):
serde-de (1):
unit::excess_element
serde-de-seq (10 - only for "overlapped-lists" feature):
variable_name::fixed_size::field_after_list::overlapped_with_nested_list
variable_name::fixed_size::field_before_list::overlapped_with_nested_list
variable_name::fixed_size::two_lists::choice_and_fixed::overlapped::with_nested_list_fixed_after
variable_name::fixed_size::two_lists::choice_and_fixed::overlapped::with_nested_list_fixed_before
variable_name::fixed_size::two_lists::fixed_and_choice::overlapped::with_nested_list_fixed_after
variable_name::fixed_size::two_lists::fixed_and_choice::overlapped::with_nested_list_fixed_before
variable_name::variable_size::field_after_list::overlapped_with_nested_list
variable_name::variable_size::field_before_list::overlapped_with_nested_list
variable_name::variable_size::two_lists::choice_and_fixed::overlapped::with_nested_list_fixed_after
variable_name::variable_size::two_lists::fixed_and_choice::overlapped::with_nested_list_fixed_after
serde-de-xsi (9, +3):
as_field::nested_nil::field::nil_on_parent
as_field::nested_nil::field::nil_on_self
as_field::nested_nil::value::nil_on_parent
as_field::nested_nil::value::nil_on_self
as_field::with_element::nested::true_
top_level_option::nested_nil::string
top_level_option::nested_nil::unit
top_level_option::with_element::ns0::true_
top_level_option::with_element::xsi::true_
d0253d3 to
0cdd7ac
Compare
|
Ok, I believe now everything was catched and analysed. |
| self.read.pop_front() | ||
| } | ||
|
|
||
| #[cfg(not(feature = "overlapped-lists"))] |
There was a problem hiding this comment.
Not immediately actionable, but Rust 1.95 has cfg_select - would be nice to use eventually.
| V: Visitor<'de>, | ||
| { | ||
| let has_nil = self.map.de.reader.reader.has_nil_attr(&self.map.start); | ||
| // `self.map.start` already was taken from the reader, so its namespace bindings already processed. |
There was a problem hiding this comment.
"its namespace bindings were already processed"
| as ` `, ` `, and `	` respectively, preventing silent data loss from | ||
| XML attribute-value normalization on round-trip. Likewise `Attribute::from` | ||
| performs the same transformation. | ||
| - [#953]: The serde `Deserializer` now correctly handle namespaces. Previously |
There was a problem hiding this comment.
Deserializer now correctly handles namespaces.
| performs the same transformation. | ||
| - [#953]: The serde `Deserializer` now correctly handle namespaces. Previously | ||
| the namespace bindings might be applied or removed before the event actually | ||
| was consumed which lead to couple of bugs. |
| /// Runs action as if all namespaces from the specified `start` element was added | ||
| /// to the resolver. Actually, resolver state remains unchanged after this call, | ||
| /// but inside the action resolver have all namespaces from the `start`. | ||
| pub fn with<F, R>(&mut self, start: &BytesStart, mut action: F) -> Result<R, NamespaceError> |
There was a problem hiding this comment.
Runs
actionas if all namespaces from the specifiedstartelement were added to the resolver, but without actually changing the resolver state.
| `normalized_value_with()` instead. | ||
| - [#1002]: Added `NamespaceResolver::with` that allows temporary apply namespace | ||
| bindings from the start tag and run query on the resolver. It is useful to check | ||
| peeked event which is not yet consumed. |
There was a problem hiding this comment.
- [Fix too early handling of namespace declarations #1002]: Added
NamespaceResolver::withthat allows temporarily applying namespace
bindings from the start tag for the scope of a provided closure F, without making any
persistent change to the resolver.
"It is useful to check a peeked event which is not yet consumed." also sounds like an internal detail - is a user going to do that?
There was a problem hiding this comment.
Because NamespaceResolver is public and intended to use with own implementations of a peekable reader, this is a note for such users.
| peeked event which is not yet consumed. | ||
| - [#1002]: Added `Deserializer::resolver` and `Deserializer::resolver_mut` methods | ||
| to get a namespace resolver used by this deserializer, because its internally no | ||
| longer uses the `NsReader`. |
There was a problem hiding this comment.
- [Fix too early handling of namespace declarations #1002]: Added
Deserializer::resolverandDeserializer::resolver_mutmethods
to get a namespace resolver used by this deserializer, because it no longer uses
anNsReaderinternally.
|
Code looks reasonable so far, still reviewing a bit, but will wait until @weiznich gives the 👍 with his dataset to finish. |
Co-authored-by: Daniel Alley <dalley@redhat.com>
weiznich
left a comment
There was a problem hiding this comment.
I've verified that this works with our dataset. Also the code looks fine to me.
Thanks for fixing this ❤️
I realized, that working with namespaces was entirely incorrect in serde
Deserializer. We push and pop namespaces when we take events from theReader, but we may buffer those events and check forxsi:nillater, when the state ofNamespaceResolverwas changed.Now
Deserializerholds theNamespaceResolverby itself and calls its methods only when event is consumed byDeserializer::next()call.Fixes #953
Closes #974
@weiznich, it would be great if you can check this PR on your data. I'm sure that the fix currently is incomplete, so I need some time to find the cases that is not covered yet. You may help with that.