-
Notifications
You must be signed in to change notification settings - Fork 123
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
Add support for \x?? and improve escapes #84
Conversation
This was a stupid mistake, fixed it now :) This is ready for review. |
r? @pyfisch |
Thanks. How about using |
That's a good idea, I'll try it out tomorrow.
|
@pyfisch Is there a reason you suggested |
@torkleyy That I like to be able to read Unicode characters. ( |
Ah, thanks for the explanation :)
|
bors delegate=pyfisch |
✌️ pyfisch can now approve this pull request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Added a few comments.
src/parse.rs
Outdated
@@ -94,7 +95,7 @@ impl<'a> Bytes<'a> { | |||
let c = self.eat_byte()?; | |||
|
|||
if c != b'\\' && c != b'\'' { | |||
return self.err(ParseError::InvalidEscape); | |||
return self.err(ParseError::InvalidEscape("TODO")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind to resolve the TODO?
src/parse.rs
Outdated
Ok(n) | ||
} | ||
|
||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the commented out code.
src/ser/mod.rs
Outdated
|
||
fn serialize_escaped_str(&mut self, value: &str) { | ||
self.output += "\""; | ||
self.output += &value.chars().flat_map(|c| c.escape_default()).collect::<String>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid the string allocation and immediately push the characters to the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err right, I was trying it out and forgot about it then. Thanks!
let s: String = (1..128).into_iter().flat_map(from_u32).collect(); | ||
|
||
check_same(s); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some test with non-ascii characters would be nice.
For example ♠
and ß
. (They should not be escaped)
src/parse.rs
Outdated
} | ||
if bytes == 0 { | ||
return self.err(ParseError::InvalidEscape( | ||
"Null character (\\u{0}) not allowed", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the null character not allowed? "foo\0bar" is a valid string in Rust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should allow it in RON though, since that would make usage in e.g. C really difficult.
src/parse.rs
Outdated
|
||
fn parse_str_escape(&mut self, store: &mut Vec<u8>) -> Result<()> { | ||
use std::iter::repeat; | ||
|
||
match self.eat_byte()? { | ||
b'\'' => store.push(b'\''), | ||
b'"' => store.push(b'"'), | ||
b'\\' => store.push(b'\\'), | ||
b'b' => store.push(b'\x08'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these escapes are no standard Rust escapes.
Okay, addressed all comments except one (about |
I don't like the current handling of NUL. Currently the string "foo\0bar" will successfully be serialized. But it will fail deserialization. My assumption is that I can serialize any Rust data type with RON and deserialize it again and get an equivalent representation. Special casing strings with a NUL character breaks this assumption. |
You're right that serialization and deserialization should allow the same things. If we decide to exclude @kvark @ozkriff @Xaeroxe What do you think about this? My main concern is that adding support for |
My primary concern is that if we exclude |
It doesn't panic, just gives you an error. And really, it doesn't make any sense to include |
C interop and serialization are somewhat orthogonal. I could see a problem with other languages implementing RON support and treating this differently. For that we should have NULL handling defined as implementation dependent. There are cases in OpenGL/Vulkan spec where they do the same: it's not undefined behavior, and it's not standard, it's a defined per implementation behavior. TL;DR: we should support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
bors delegate+ Merge it after squashing. |
✌️ torkleyy can now approve this pull request |
Add support for "\x??" Add more tests, fix bug Finish string escapes Add non ascii test, fix nits Remove non-standard escapes Implement char escapes Allow NUL
bors r=pyfisch |
Build succeeded |
This PR seems to contain a regression.Fixes #82