Do not duplicate a non-ASCII space when wrapping - #275
Open
dylanpulver wants to merge 1 commit into
Open
Conversation
In convert_p's wrap branch, `trailing` is captured with a bare rstrip() and then appended after fill(). Bare rstrip() removes every character str.isspace() calls whitespace, but fill() only strips the ASCII ones, so a trailing U+00A0 (or U+202F, U+2007, U+2003, U+2009, U+3000) is left in place by fill() and then appended a second time. `<p>a <br>c</p>` with wrap=True gives 'a\xa0\xa0 \nc' where wrap=False gives 'a\xa0 \nc'. Restricting the rstrip to the same ' \t\r\n' set fill() uses makes the two agree.
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.
convert_p's wrap branch captures trailing whitespace with a barerstrip()and re-appends it afterfill():Bare
rstrip()removes everythingstr.isspace()accepts, butfill()only strips the ASCII set — so a trailing U+00A0 is left in place byfill()and appended again. One in, two out.What I ran. With a
wrap_widthtoo wide to wrap anything,wrap=Trueshould equalwrap=False. 96 documents — 8 trailing characters × 3 bodies × 2newline_style× with/without<br>— compared between the two settings, same command ondevelopand on the patch:develop(bc98c9e)All 18 are duplications, in six characters: U+00A0, U+202F, U+2007, U+2003, U+2009, U+3000. ASCII space and the no-trailing-character case are the controls and match in both trees.
pytest83 passed before and after; the added assertion fails on unpatched source.flake8 --ignore=E501,W503clean.The alternative I rejected. Wrapping
line_no_trailinginstead oflinealso gives 0/96, and it's arguably the more obvious reading. It differs once the line actually wraps: atwrap_width=8,<p>aaa bbbb <br>c</p>givesaaa\nbbbb\xa0— longest content line 5aaa bbbb\xa0— longest content line 9, over the requested widthbecause it hands
fill()a string with the U+00A0 already removed, so the width calculation doesn't see it. A no-break space occupies a column like any other, so I kept it inside thefill()input. Happy to switch if you'd rather.Deliberately not touched. The
rstrip()inprocess_textis the other half of the pair #188 converted, and #188 said explicitly that the trailing side is an open question — "or, conversely, where trailing such spaces could safely be stripped even if they no longer are after this change" — so that one is yours to decide, and this change doesn't depend on it. This also does not fix #175: that report goes throughchomp(), which is untouched here (<div>this is a <i>test </i>with whitespaces</div>is unchanged by this patch).AI assistance: found and patched with Claude Code (Claude Opus 5,
claude-opus-5); I reviewed and ran everything above myself.