Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T6111: Fix modification of String.escaped to leave UTF-8 bytes unescaped #23

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

jestabro
Copy link
Contributor

@jestabro jestabro commented Mar 8, 2024

The existing fix still passed the string as a whole to Bytes.escaped (as does the standard library function): the exemption of chars with high bit set needs to occur in Bytes.escaped as well, otherwise a string containing, say, a unicode char and a backslash would still escape the unicode character, confounding the translation in T5996 (vyos/vyos-1x#3035).

It's not pretty, but nor are the stdlib functions. The related fixes in T5996 and T6111 should address the matter until we have a cleaner solution for unicode support.

src/util.ml Outdated
let a = char_code c in
B.unsafe_set s' !n '\\';
incr n;
B.unsafe_set s' !n (char_chr (48 + a / 100));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move 48 to a constant with some descriptive name to make the code easier to read for someone who doesn't remember the details of the encoding offhand.

Copy link
Contributor Author

@jestabro jestabro Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to leave the function as close to the stdlib version as possible to aid readability by comparison, mutatis mutandis, but I can make the change.

The existing fix still passed the string as a whole to Bytes.escaped (as
does the standard library function): the exemption of chars with high
bit set needs to occur in Bytes.escaped as well.
@jestabro jestabro requested a review from dmbaturin March 12, 2024 16:32
@dmbaturin dmbaturin merged commit 8472046 into vyos:master Mar 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants