Repository navigation
Conversation
string.__new__ decodes bytes, but uri.__init__ passed the original argument to urlparse, which decodes bytes as ASCII. A uri created from bytes with a non-ASCII character raised a UnicodeDecodeError, for example for URLs of the browser history plugins of dissect.target. For ASCII bytes the parts (hostname, path and so on) were bytes, not str. Parse the decoded string, as the string type does. Related to fox-it/dissect.target#1947
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
string.__new__decodesbytes(witherrors="surrogateescape"), buturi.__init__passed the original argument tourlparse.urlparsedecodesbytesas ASCII, so auricreated from bytes had two problems:UnicodeDecodeError, which stops a producer that builds records in a generator. For example the browser history plugins of dissect.target pass the UTF-8 bytes returned bytry_idnato aurifield, see iexplore.history raises UnicodeDecodeError on URLs that are not IDNA-encodable (try_idna returns bytes for a uri field) dissect.target#1947.hostname,path, ...) werebytes, although they are annotated-> str.Change
uri.__init__parsesstr(self), the string thatstring.__new__already built, instead of the argument. Input that is astris unchanged. Input that isbytesnow givesstrparts, and bytes that are not valid UTF-8 are kept the way thestringtype keeps them.Behaviour change:
uri(<bytes>).hostname,.pathand the other parts arestrand no longerbytes. I found nothing in flow.record or dissect.target that reads them asbytes.Tests
test_uri_type_bytesintests/fieldtypes/test_fieldtypes.py: ASCII bytes, UTF-8 bytes with a non-ASCII character, and bytes that are not valid UTF-8. Without the change it fails (hostnameisb'www.google.com'); with it theuritests pass. The rest of the suite has the same failures with and without the change in my environment (17 intests/tools/test_rdump.pyand 1 intests/test_regressions.py, and three adapter test files whose optional packages are not installed).ruff checkandruff format --checkare clean.Related to fox-it/dissect.target#1947