Isolated surrogates are not replaced when encoding to / from utf-8
Isolated (unpaired) surrogates should be treated as encoding errors.
Example:
% binary encode hex [encoding convertto -profile strict utf-8 \UD800]
unexpected character at index 0: 'U+00D800'
The above is correct as U+D800 should not appear as an isolated surrogate code point. However the following is not,
% binary encode hex [encoding convertto -profile replace utf-8 \UD800]
eda080
eda080 is the utf-8 for U+D800. The output have been efbfbd (U+FFFD replacement char).
In principle, any time the strict profile raises an error, the replace profile should be substituting the replacement character.
Jan, your thoughts?
f80e5914e9Merge [ab1f0c7834fd0e4b]: Add test cases for [80d4c1c7e5]. check-in2024-08-25 11:15:1670e3598165Merge [d7ef8a68d7a2cdb5]: Fix [80d4c1c7e5]: Isolated surrogates are not replaced when encoding to / from utf-8. check-in2024-08-25 11:08:0944cc6f2c62(cherry-pick): Add test cases for [80d4c1c7e5] check-in2024-02-07 08:50:01ab1f0c7834Add test cases for [80d4c1c7e5] check-in2024-02-07 03:06:05d7ef8a68d7Fix [80d4c1c7e5]: Isolated surrogates are not replaced when encoding to / from utf-8 check-in2024-02-06 13:22:59c37652549eProposed fix for [80d4c1c7e5]: Isolated surrogates are not replaced when encoding to / from utf-8 check-in2024-02-06 13:01:11
It looks like you forgot the "-profile replace" handling here:
https://core.tcl-lang.org/tcl/file?name=generic/tclEncoding.c&ci=f1cef9d6c96f7ce5&ln=2595-2607
Agreed
Hmmmm. I now see the PROFILE_REPLACE handling just above that ...... I don't know why it's not working as expected then.
Proposed fix [here]
In 8.7 it appears to work as expected, but in 9.0 "-profile replace" handling was lacking for this specific case.
Do you want to add a testcase?
Fix seems reasonable. If you commit it, I'll the test cases.
Committed now
Added tests. Closing.