Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2024-08-25
11:15
Merge [ab1f0c7834fd0e4b]: Add test cases for [80d4c1c7e5]. check-in: f80e5914e9 user: pooryorick tags: unchained, INCOMPATIBLE_LICENSE
11:08
Merge [d7ef8a68d7a2cdb5]: Fix [80d4c1c7e5]: Isolated surrogates are not replaced when encoding to / ... check-in: 70e3598165 user: pooryorick tags: unchained, INCOMPATIBLE_LICENSE
2024-02-07
08:50
(cherry-pick): Add test cases for [80d4c1c7e5] check-in: 44cc6f2c62 user: jan.nijtmans tags: core-8-branch
03:09 • Closed ticket [80d4c1c7e5]: Isolated surrogates are not replaced when encoding t... artifact: abdf6c0c39 user: apnadkarni
03:06
Add test cases for [80d4c1c7e5] check-in: ab1f0c7834 user: apnadkarni tags: trunk, main
2024-02-06
13:23 • Pending ticket [80d4c1c7e5]: Isolated surrogates are not replaced when encoding ... artifact: 80a06ba234 user: jan.nijtmans
13:22
Fix [80d4c1c7e5]: Isolated surrogates are not replaced when encoding to / from utf-8 check-in: d7ef8a68d7 user: jan.nijtmans tags: trunk, main
13:22 • Ticket [80d4c1c7e5] Isolated surrogates are not replaced when encoding to / from... artifact: 5d1deab796 user: jan.nijtmans
13:15 • Ticket [80d4c1c7e5]: 3 changes artifact: 6f1c99cea5 user: apnadkarni
13:03 • Ticket [80d4c1c7e5]: 4 changes artifact: 763b0c84f0 user: jan.nijtmans
13:01
Proposed fix for [80d4c1c7e5]: Isolated surrogates are not replaced when encoding to / from utf-8 closed check-in: c37652549e user: jan.nijtmans tags: bug-80d4c1c7e5
12:30 • Ticket [80d4c1c7e5] Isolated surrogates are not replaced when encoding to / from... artifact: 3339fafbd6 user: jan.nijtmans
12:18 • Ticket [80d4c1c7e5]: 3 changes artifact: 2500439b30 user: jan.nijtmans
11:38 • New ticket [80d4c1c7e5]. artifact: 4736f5b7db user: apnadkarni

Isolated surrogates are not replaced when encoding to / from utf-8

Closed / Fixed80d4c1c7e5393907df677e56ccc41bb78ffafe19Created 3 years agoUpdated 3 years ago
Descriptionmarkdown2024-02-06 11:38:47

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?

Referenced by6
jan.nijtmanswiki2024-02-06 12:18:45

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

jan.nijtmanswiki2024-02-06 12:30:54

Hmmmm. I now see the PROFILE_REPLACE handling just above that ...... I don't know why it's not working as expected then.

jan.nijtmanswiki2024-02-06 13:03:41

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?

apnadkarniplain2024-02-06 13:15:28
Fix seems reasonable. If you commit it, I'll the test cases.
jan.nijtmanswiki2024-02-06 13:22:55

Committed now

jan.nijtmans Pending ticket [80d4c1c7e5]. [History diff]2024-02-06 13:23:58
apnadkarniplain2024-02-07 03:09:46
Added tests. Closing.
Log in (anonymous is fine) to add a comment.