Drop lone surrogates in the Cython quoter to match the pure-Python backend#1751
Open
rodrigobnogueira wants to merge 2 commits into
Open
Drop lone surrogates in the Cython quoter to match the pure-Python backend#1751rodrigobnogueira wants to merge 2 commits into
rodrigobnogueira wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1751 +/- ##
=======================================
Coverage 99.86% 99.86%
=======================================
Files 21 21
Lines 4310 4325 +15
Branches 252 252
=======================================
+ Hits 4304 4319 +15
Misses 4 4
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ckend The Cython quoter left a lone surrogate code point in the output when it was the only character that needed handling, because the surrogate branch of _write_utf8 returned without marking the writer changed. The pure-Python quoter has always dropped surrogates via errors="ignore", so the two backends produced different output for the same input. Mark the writer changed so the C quoter also drops them, which keeps the backends consistent and restores the invariant that raw_path is ASCII-encodable.
640d40f to
b22c9c3
Compare
Coverage Report for CI Build 27182468552Coverage increased (+0.003%) to 98.743%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
test_quote_drops_surrogate_with_encoded_char passes on the unpatched C build because "é" forces a rewrite on its own, so it is a parity guard for the mixed case rather than the isolated regression guard; relabel it and point at test_quote_drops_lone_surrogate. Reword the news fragment so it no longer implies the old C quoter dropped lone surrogates unconditionally (it only retained one when it was the sole character forcing a rewrite).
5 tasks
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.
What do these changes do?
The Cython quoting backend kept a lone Unicode surrogate code point
(
U+D800..U+DFFF) in its output when the surrogate was the onlycharacter that needed handling, because the surrogate branch of
_write_utf8returned without marking the writer as changed. Thepure-Python quoter has always dropped surrogates via
str.encode("utf8", errors="ignore"), so the two backends produceddifferent output for the same input. The C quoter now drops lone
surrogates as well, so both backends agree.
Are there changes in behavior for the user?
Yes, on the compiled extension only: quoted components (for example
URLpaths) built from strings containing lone surrogates no longerretain them; the result is plain ASCII, matching the pure-Python build.
This also restores the invariant that
raw_pathis alwaysASCII-encodable.
Is it a substantial burden for the maintainers to support this?
No. It is a one-line change in
yarl/_quoting_c.pyxthat brings the Cquoter in line with the existing pure-Python behaviour; there is no
public API change.
Related issue number
No public issue; this corrects an inconsistency between the two quoting
backends.
Checklist
CONTRIBUTORS.txt(N/A; file not present in repo)CHANGES/folderTest details (optional, for reviewers)
Tests (both backends):
python -m pytest tests/test_quoting.py tests/test_url_parsing.py, and the same withYARL_NO_EXTENSIONS=1; all pass. The two newtest_quoting.pycases run under both thepy_quoterandc_quoterfixtures and fail on the unpatched C extension, confirming they catch the regression. Pre-commit (ruff, codespell, cython-lint, mypy) passes on the changed files; the docs spell check reports only pre-existing words unrelated to this change.