Fix escaped, escaped_transform, satisfy, one_of and none_of interpreting [u8] as UTF-8 (#1679)
#1864
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix a number of issues relating to
nomdecoding[u8]buffers as UTF-8 when it shouldn't (#1679):escaped,escape_transformnow acceptcontrol_char: impl AsChar, rather thanchar.This allows the functions to be used with a
u8orb'', which is useful for parsing text-like files that contain binary or non-UTF-8 data (like Lua).escaped,escaped_transform,satisfy,one_ofandnone_ofnow iterate over individual bytes when using a[u8]input, rather than attempting to interpret bytes as UTF-8 sequences.I've added many tests demonstrating some edge cases of these functions. Many existing tests incorrectly used
strfor[u8]inputs in some places, which can lead to some unexpected behaviour when handling binary data.This will probably break API compatibility for a parser that takes a
[u8]buffer as inputs and assumes everything is decoded as UTF-8. I'd argue this is incorrect usage anyway – those should be usingstr.There's probably other parts of
nomthat assume[u8]is encoded as UTF-8, but searching for these is hard.