Skip to content

Fix percent-encoding of GS1 Digital Link URI path segments - #455

Merged
jodal merged 4 commits into
jodal:mainfrom
36taransingh5-dotcom:patch-2
Oct 25, 2026
Merged

jodal merged 4 commits into
jodal:mainfrom
36taransingh5-dotcom:patch-2

Conversation

@36taransingh5-dotcom

Copy link
Copy Markdown
Contributor

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 number ABC/DEF produced https://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:

ParseError: Expected even number of path segments, got '/01/09521234543213/21/ABC/DEF'.

GS1DigitalLinkURI.parse() never percent-decoded path segments, so a correctly encoded URI https://id.gs1.org/01/09521234543213/21/ABC%2FDEF parsed to the literal value ABC%2FDEF instead of ABC/DEF.

Fix

  • _build_uri(): quote() each path segment value with safe="" (primary identifier and qualifiers).
  • parse(): split the raw path into segments first, then unquote() 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), and ruff check/ruff format are clean.

Disclosure: this change was developed with AI assistance; I reviewed and tested it locally before submitting.

@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5e5299b) to head (81fc98a).
⚠️ Report is 5 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 "/".
@jodal
jodal merged commit 41cc2aa into jodal:main Oct 25, 2026
13 checks passed
@jodal

jodal commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Thanks!

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.

2 participants