Repository navigation
fix: escape bidirectional control characters in log fields - #392
Open
UlisesGascon wants to merge 2 commits into
Open
UlisesGascon wants to merge 2 commits into
UlisesGascon wants to merge 2 commits into
Conversation
escapeLogField already escapes C0/C1 controls and the U+2028/U+2029 line separators; extend the same handling to the Unicode bidirectional format controls (U+061C, U+200E/200F, U+202A-202E, U+2066-2069) so a field cannot reorder how a log line renders. Emitted as \uXXXX like the other controls.
krzysdz
approved these changes
Oct 15, 2026
krzysdz
left a comment
There was a problem hiding this comment.
I thought about it in June, but realistically there are many other characters that can mess up how things are seen by people (homoglyphs, modifiers, symmetric swapping (U+206B)1). Fortunately, these should not be mistaken for something else by software (like e.g. NEL/LS/PS being treated as newline by Python's str.splitlines()) and some text editors mark them to prevent improper interpretation by people.
I think that it may help in some situations, but fooling people into misinterpreting text will still be possible.
Footnotes
-
This causes e.g.
(to be displayed as)or could be used to swap[and]that the date is wrapped in, and generally applies to pairs of Bidi Mirrored characters. ↩
Co-authored-by: krzysdz <12915102+krzysdz@users.noreply.github.com>
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.
escapeLogFieldalready neutralizes C0/C1 control characters and the U+2028 / U+2029 line separators so a logged field stays on a single line. The Unicode bidirectional format controls (U+061C, U+200E/200F, U+202A-202E, U+2066-2069) aren't covered, yet they can reorder how a log line renders in a terminal or editor, making the recorded value misleading. This extends the same character class to escape them as\uXXXX, consistent with the existing controls, and adds a regression test (delivered via the:remote-usertoken, matching the existing escaping tests).