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

More strict deserialization into primitives #661

Merged
merged 4 commits into from
Oct 7, 2023

Conversation

Mingun
Copy link
Collaborator

@Mingun Mingun commented Oct 6, 2023

This PR restricts ability to deserialize primitive types (numbers, booleans, characters, strings) from XML documents that contains a trailing tag after a text. Previously the error emitted only when tag was before text.

Before that PR the XML

<struct>
  <field>42<something-wrong/></field>
</struct>

can be successfully deserialized into

struct Struct {
  field: u32,
}

which is not that you want generally. Now the DeError::UnexpectedStart error is returned. Also, probably we want that 42<something-wrong/> was passed to the u32::deserialize and deserialization fail because type decide that (for example, we might want to capture tag in String), but this would be possible only when #257 would be implemented.

New tests will be added in the following commit

(review with "ignore whitespace changes mode" on)
failures (72):
    trivial::cdata::char_::field
    trivial::cdata::char_::primitive
    trivial::cdata::f32_::field
    trivial::cdata::f32_::primitive
    trivial::cdata::f64_::field
    trivial::cdata::f64_::primitive
    trivial::cdata::false_::field
    trivial::cdata::false_::primitive
    trivial::cdata::i128_::field
    trivial::cdata::i128_::primitive
    trivial::cdata::i16_::field
    trivial::cdata::i16_::primitive
    trivial::cdata::i32_::field
    trivial::cdata::i32_::primitive
    trivial::cdata::i64_::field
    trivial::cdata::i64_::primitive
    trivial::cdata::i8_::field
    trivial::cdata::i8_::primitive
    trivial::cdata::isize_::field
    trivial::cdata::isize_::primitive
    trivial::cdata::string::field
    trivial::cdata::string::primitive
    trivial::cdata::true_::field
    trivial::cdata::true_::primitive
    trivial::cdata::u128_::field
    trivial::cdata::u128_::primitive
    trivial::cdata::u16_::field
    trivial::cdata::u16_::primitive
    trivial::cdata::u32_::field
    trivial::cdata::u32_::primitive
    trivial::cdata::u64_::field
    trivial::cdata::u64_::primitive
    trivial::cdata::u8_::field
    trivial::cdata::u8_::primitive
    trivial::cdata::usize_::field
    trivial::cdata::usize_::primitive
    trivial::text::char_::field
    trivial::text::char_::primitive
    trivial::text::f32_::field
    trivial::text::f32_::primitive
    trivial::text::f64_::field
    trivial::text::f64_::primitive
    trivial::text::false_::field
    trivial::text::false_::primitive
    trivial::text::i128_::field
    trivial::text::i128_::primitive
    trivial::text::i16_::field
    trivial::text::i16_::primitive
    trivial::text::i32_::field
    trivial::text::i32_::primitive
    trivial::text::i64_::field
    trivial::text::i64_::primitive
    trivial::text::i8_::field
    trivial::text::i8_::primitive
    trivial::text::isize_::field
    trivial::text::isize_::primitive
    trivial::text::string::field
    trivial::text::string::primitive
    trivial::text::true_::field
    trivial::text::true_::primitive
    trivial::text::u128_::field
    trivial::text::u128_::primitive
    trivial::text::u16_::field
    trivial::text::u16_::primitive
    trivial::text::u32_::field
    trivial::text::u32_::primitive
    trivial::text::u64_::field
    trivial::text::u64_::primitive
    trivial::text::u8_::field
    trivial::text::u8_::primitive
    trivial::text::usize_::field
    trivial::text::usize_::primitive
… return error instead of returning `text`

when deserialize into primitive types (ex. `u32`, but not struct S { #[serde(rename = "$text")] field: u32 })
@Mingun Mingun added bug serde Issues related to mapping from Rust types to XML labels Oct 6, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #661 (9a354d7) into master (dd34cab) will increase coverage by 0.00%.
The diff coverage is 83.33%.

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

@@           Coverage Diff           @@
##           master     #661   +/-   ##
=======================================
  Coverage   64.60%   64.61%           
=======================================
  Files          36       36           
  Lines       17290    17294    +4     
=======================================
+ Hits        11170    11174    +4     
  Misses       6120     6120           
Flag Coverage Δ
unittests 64.61% <83.33%> (+<0.01%) ⬆️

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

Files Coverage Δ
src/de/mod.rs 69.42% <83.33%> (+0.05%) ⬆️

@Mingun Mingun merged commit c79ad58 into tafia:master Oct 7, 2023
6 checks passed
@Mingun Mingun deleted the strict-de-of-primitives branch October 7, 2023 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants