Skip to content

Commit

Permalink
Merge pull request #387 from Mingun/seq
Browse files Browse the repository at this point in the history
Fix errors in sequence deserialization
  • Loading branch information
Mingun committed Jun 5, 2022
2 parents 02ba9a8 + 59a5c76 commit 0a42987
Show file tree
Hide file tree
Showing 9 changed files with 3,465 additions and 56 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Expand Up @@ -40,6 +40,10 @@ jobs:
env:
LLVM_PROFILE_FILE: coverage/serialize-escape-html-%p-%m.profraw
run: cargo test --features serialize,escape-html
- name: Run tests (all features)
env:
LLVM_PROFILE_FILE: coverage/all-features-%p-%m.profraw
run: cargo test --all-features
- name: Prepare coverage information for upload
if: runner.os == 'Linux'
run: |
Expand Down
46 changes: 46 additions & 0 deletions Cargo.toml
Expand Up @@ -42,6 +42,52 @@ default = []
## [standard compliant]: https://www.w3.org/TR/xml11/#charencoding
encoding = ["encoding_rs"]

## This feature enables support for deserializing lists where tags are overlapped
## with tags that do not correspond to the list.
##
## When this feature is enabled, the XML:
## ```xml
## <any-name>
## <item/>
## <another-item/>
## <item/>
## <item/>
## </any-name>
## ```
## could be deserialized to a struct:
## ```ignore
## #[derive(Deserialize)]
## #[serde(rename_all = "kebab-case")]
## struct AnyName {
## item: Vec<()>,
## another_item: (),
## }
## ```
##
## When this feature is not enabled (default), only the first element will be
## associated with the field, and the deserialized type will report an error
## (duplicated field) when the deserializer encounters a second `<item/>`.
##
## Note, that enabling this feature can lead to high and even unlimited memory
## consumption, because deserializer should check all events up to the end of a
## container tag (`</any-name>` in that example) to figure out that there are no
## more items for a field. If `</any-name>` or even EOF is not encountered, the
## parsing will never end which can lead to a denial-of-service (DoS) scenario.
##
## Having several lists and overlapped elements for them in XML could also lead
## to quadratic parsing time, because the deserializer must check the list of
## events as many times as the number of sequence fields present in the schema.
##
## To reduce negative consequences, always [limit] the maximum number of events
## that [`Deserializer`] will buffer.
##
## This feature works only with `serialize` feature and has no effect if `serialize`
## is not enabled.
##
## [limit]: crate::de::Deserializer::event_buffer_size
## [`Deserializer`]: crate::de::Deserializer
overlapped-lists = []

## Enables support for [`serde`] serialization and deserialization
serialize = ["serde"]

Expand Down
11 changes: 11 additions & 0 deletions Changelog.md
Expand Up @@ -10,10 +10,19 @@

## Unreleased

### New Features

- [#387]: Allow overlapping between elements of sequence and other elements
(using new feature `overlapped-lists`)

### Bug Fixes

- [#9]: Deserialization erroneously was successful in some cases where error is expected.
This broke deserialization of untagged enums which rely on error if variant cannot be parsed
- [#387]: Allow to have an ordinary elements together with a `$value` field
- [#387]: Internal deserializer state can be broken when deserializing a map with
a sequence field (such as `Vec<T>`), where elements of this sequence contains
another sequence. This error affects only users with the `serialize` feature enabled

### Misc Changes

Expand All @@ -36,9 +45,11 @@
### New Tests

- [#9]: Added tests for incorrect nested tags in input
- [#387]: Added a bunch of tests for sequences deserialization

[#8]: https://github.com/Mingun/fast-xml/pull/8
[#9]: https://github.com/Mingun/fast-xml/pull/9
[#387]: https://github.com/tafia/quick-xml/pull/387
[#391]: https://github.com/tafia/quick-xml/pull/391

## 0.23.0 -- 2022-05-08
Expand Down

0 comments on commit 0a42987

Please sign in to comment.