Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Use -strict to disable noncharacters

Closed / Rejected084ab982fea4c32aaab57251eeea0d7c829893a0Created 4 years agoUpdated 4 years ago
Descriptionwiki2022-11-29 11:51:32
Request, initiated by Rolf Ade.
Look at this:

% info patchlevel 9.0a4 % encoding system utf-8 % puts \uffff error writing "stdout": illegal byte sequence

Although this was on purpose, TIP #346 could be used to reduce the surprise here: When -strictencoding is specified, disallow non-characters, otherwise allow them. The same will be done on 'encoding convertto utf-8' as well. (since the -strict handling is built-in in the utf-8 encoder/decoder)

Referenced by5
  • b7da2f7465Follow-up for [084ab982fe]: Use -strict to disable noncharacters. This change was only done for utf-8, but the same change should be done for utf-16 and utf-32 too check-in2022-12-16 09:40:03
  • af5373e31bClosed ticket [17a1cb8d6e]: Tcl 9: "illegal byte sequence" ?! plus 7 other changes ticket2022-12-13 07:59:45
  • 9619dddce6Fix for [084ab982fe]: Use -strict to disable noncharacte check-in2022-11-30 10:48:40
  • 30a22094e9Ticket [084ab982fe] Use -strict to disable noncharacters status still Open with 4 other changes ticket2022-11-29 17:22:09
  • ec0c7045dfProposed fix for [084ab982fe]: Use -strict to disable noncharacters check-in2022-11-29 14:51:03
jan.nijtmans Ticket [084ab982fe]: 3 changes [History diff]2022-11-29 11:53:59
oehharwiki2022-11-29 17:22:09

Great implementation with test-cases in light speed by Jan: [084ab982fe]

Thank you, I appreciate, Harald

jan.nijtmanswiki2022-12-01 07:46:22

Fixed [here]

pointsmanplain2022-12-02 12:14:29
One thing is probably not made clear enough by me (probably because I'm in fact try to not sound "a little sharp on the vocal level", although sometimes obviously failing).

Why do we have the fconfigure -strict mode at all? 

The current default is "strict" in the sense of eg. python, that means: raise error on surrogate. Addionally there is -nocomplain, passing all code-points through. Both modes are fine and understandable to have.

Additionally we the mode -strict 1 (which is a bit a confusing name) which raises error on surrogate and noncharacter.

This surely is a "feature" in the sense it has a defined behaviour. But what is the use case? Who needs this? Is this not an more obscure than just minor feature?

Especially since there is also the [string is unicode] feature. An IMHO gross misnomer, did I said this already?

If someone wants the behaviour this fconfigure -strict 1 feature provides one can always do

if {[string is unicode $mystring]} {
    puts $chan $mystring
} else {
    # Handle case of mystring with noncharacter
}

instead of 

if {[catch {puts $chan $mystring}]} {
    # Handle case of mystring with noncharacter
}
jan.nijtmanswiki2022-12-02 12:42:39

> Additionally we the mode -strict 1 (which is a bit a confusing name) which raises error on surrogate and noncharacter.

The "-strict 1" mode does more than only raising errors on noncharacters. The default utf-8 decoder tries to correct obvious error, in 'strict' mode it doesn't do that any more. e.g.:

$ tclsh9.0
% encoding convertfrom utf-8 \xA1
ยก
% encoding convertfrom -strict utf-8 \xA1
unexpected byte sequence starting at index 0: '\xA1'
%

'-strict 1' mode is a flag, whose behavior is implemented by every encoder/decoder separately.

jan.nijtmanswiki2022-12-16 09:41:45

Follow-up [here]. If we change the behavior of -strict for utf-8, we should do the corresponding change on utf-16 and utf-32 too.

pooryorickwiki2022-12-26 20:31:11

Overloading -strict for this purpose is incorrect, as -strict should be dedicated to how to handle invalid data in an encoding, not on choosing which data to consider invalid. This is a separate concern that should be handled by separate options. By default, an encoder/decoder should conform to the specification, and options can be provided to direct the encoder/decoder to deviate in some way. In this case, a suitable option might be -onlychars 1, with the default being -onlychars 0 to conform to the specification. There could be additional options such as -surrogates 1 (default is -surrogates 0) and -nonchars 0 (default is -nonchars 1). This is more complicated, but oversimplification can be a bad thing. The Unicode specification entails a certain amount of complexity, and there is no way around that. In the case of Unicode, the proper target for Tcl is fidelity.

jan.nijtmanswiki2022-12-29 23:42:32

pooryorick's last comment is out-of-date, since the behavior of -strict is already modified to be more conform 'strict'-ness as described by the Unicode consortium. So, closing (again)

pooryorickwiki2022-12-30 20:41:45

See issue report [17a1cb8d6e2a51bd] for further details.

Log in (anonymous is fine) to add a comment.