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 parsing of borrowed strings #228

Merged
merged 1 commit into from May 8, 2020
Merged

Conversation

caelunshun
Copy link
Contributor

@caelunshun caelunshun commented May 8, 2020

The implementation of deserialize_str would incorrectly call Visitor::visit_str when it should have called Visitor::visit_borrowed_str. As per https://serde.rs/lifetimes.html#transient-borrowed-and-owned-data, visit_borrowed_str should be called when the lifetime of the deserialized string is that of the input.

This should not be a breaking change, because it only extends the lifetime of the deserialized string. The default implementation of Visitor::visit_borrowed_str forwards to visit_str, meaning that this commit only enables more flexibility.

I added a test in tests/borrowed_str.rs which demonstrates this behavior. Prior to this change, the test would fail.

The implementation of `deserialize_str` would incorrectly
call `Visitor::visit_str` when it should have called
`Visitor::visit_borrowed_str`. As per https://serde.rs/lifetimes.html#transient-borrowed-and-owned-data,
`visit_borrowed_str` should be called when the lifetime of the deserialized
string is that of the input.

This should not be a breaking change, because it only adds more guarantees
to the lifetime of the deserialized string. The default implementation
of `Visitor::visit_borrowed_str` forwards to `visit_str`, meaning
that this change only enables more flexibility.
kvark
kvark approved these changes May 8, 2020
Copy link
Collaborator

@kvark kvark left a comment

Seems reasonable, thank you!
bors r+

@bors
Copy link
Contributor

bors bot commented May 8, 2020

Build succeeded:

@bors bors bot merged commit 0a7d83d into ron-rs:master May 8, 2020
5 checks passed
@caelunshun caelunshun deleted the borrowed-str branch May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants