Repository navigation
Fix percent-encoding of GS1 Digital Link URI path segments - #455
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #455 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 16 16
Lines 1298 1299 +1
Branches 143 143
=========================================
+ Hits 1298 1299 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
GS1 element string values can legally contain characters that are reserved in URIs, such as "/" (part of the GS1 AI encodable character set used by AIs like 10, 21, 8010, ...). _build_uri() placed those values raw into the URI path, so a serial number like "ABC/DEF" produced .../21/ABC/DEF, an invalid Digital Link that even biip's own parser rejected with "Expected even number of path segments". parse() never percent-decoded path segments, so a spec-correct URI like .../21/ABC%2FDEF yielded the literal value "ABC%2FDEF". Build: quote() each path segment value with safe="". Parse: split the raw path first, then unquote() each segment, so an encoded "/" (%2F) inside a value does not create a phantom separator.
Regression tests for parsing percent-encoded path segments, encoding reserved characters when building URIs, and full round trips of values containing "/".
Owner
|
Thanks! |
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.
Problem
GS1 element string values can legally contain characters that are reserved in URIs. "/" is part of the GS1 AI encodable character set and is valid in values for AIs such as 10 (BATCH/LOT) and 21 (SERIAL). Both directions of the Digital Link URI handling mishandled such values:
_build_uri()placed values raw into the URI path. A serial numberABC/DEFproducedhttps://id.gs1.org/01/09521234543213/21/ABC/DEF, which is not a valid Digital Link URI for that message - even biip's own parser rejects it:GS1DigitalLinkURI.parse()never percent-decoded path segments, so a correctly encoded URIhttps://id.gs1.org/01/09521234543213/21/ABC%2FDEFparsed to the literal valueABC%2FDEFinstead ofABC/DEF.Fix
_build_uri():quote()each path segment value withsafe=""(primary identifier and qualifiers).parse(): split the raw path into segments first, thenunquote()each segment, so an encoded "/" (%2F) inside a value does not create a phantom path separator.Query string components were already symmetric (
urlencode/parse_qs) and are unchanged.Tests
Added parametrized regression tests covering: parsing percent-encoded path segments, percent-encoding reserved characters when building URIs, and full serialize/parse round trips of values containing "/". All 532 existing tests plus the new tests pass locally (
pytest tests/, Python 3.12), andruff check/ruff formatare clean.Disclosure: this change was developed with AI assistance; I reviewed and tested it locally before submitting.