Diff
Not logged in

Differences From Artifact [067329a007]:

To Artifact [b890ebd7af]:


9094
9095
9096
9097
9098
9099
9100

9101
9102
9103
9104

9105

9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118

9119

9120
9121
9122
9123


9124
9125
9126
9127
9128
9129
9130
9094
9095
9096
9097
9098
9099
9100
9101
9102



9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119

9120
9121
9122


9123
9124
9125
9126
9127
9128
9129
9130
9131







+

-
-
-
+

+













+
-
+


-
-
+
+







    # \x81 is invalid in utf-8
    puts -nonewline $f A\x81
    flush $f
    seek $f 0
    fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf -encodingstrict 1
} -body {
    set status [catch {read $f} cres copts]
    set d [dict get $copts -result]
    binary scan $d H* hd
    lappend hd [catch {read $f} msg]
    close $f
    lappend hd $msg
    lappend hd $status $cres
} -cleanup {
    close $f
    removeFile io-75.6
} -match glob -result {41 1 {error reading "*": illegal byte sequence}}

test io-75.7 {invalid utf-8 encoding eof handling (-encodingstrict 1)} -setup {
    set fn [makeFile {} io-75.7]
    set f [open $fn w+]
    fconfigure $f -encoding binary
    # \xA1 is invalid in utf-8. -eofchar is not detected, because it comes later.
    puts -nonewline $f A\xA1\x1A
    flush $f
    seek $f 0
    fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A -translation lf -encodingstrict 1
} -body {
    set status [catch {read $f} cres copts]
    set d [read $f]
    set d [dict get $copts -result]
    binary scan $d H* hd
    lappend hd [eof $f]
    lappend hd [catch {read $f} msg]
    lappend hd $msg
    lappend hd $status
    lappend hd $cres
    fconfigure $f -encoding iso8859-1
    lappend hd [read $f];# We changed encoding, so now we can read the \xA1
    close $f
    set hd
} -cleanup {
    removeFile io-75.7
} -match glob -result {41 0 1 {error reading "*": illegal byte sequence} ยก}
9159
9160
9161
9162
9163
9164
9165
9166

9167
9168
9169

9170
9171
9172
9173
9174
9175
9176
9177

9178

9179
9180



9181

9182
9183
9184

9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200

9201

9202
9203
9204


9205
9206
9207
9208
9209
9210




















9211
9212
9213
9214
9215
9216
9217


9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235

9236

9237
9238

9239
9240

9241
9242
9243
9244
9245
9246
9247
9160
9161
9162
9163
9164
9165
9166

9167


9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178

9179
9180
9181
9182
9183
9184

9185
9186
9187

9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205

9206
9207


9208
9209
9210
9211
9212
9213
9214

9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240

9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261

9262
9263

9264
9265

9266
9267
9268
9269
9270
9271
9272
9273







-
+
-
-

+








+
-
+


+
+
+
-
+


-
+
















+
-
+

-
-
+
+





-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
+
+


















+
-
+

-
+

-
+







    seek $f 0
    list [read $f] $msg
} -cleanup {
    close $f
    removeFile io-75.9
} -match glob -result [list A {error writing "*": illegal byte sequence}]

# Incomplete sequence test.

# This error may IMHO only be detected with the close.
# But the read already returns the incomplete sequence.
test io-75.10 {incomplete multibyte encoding read is ignored} -setup {
	set res {}
    set fn [makeFile {} io-75.10]
    set f [open $fn w+]
    fconfigure $f -encoding binary
    puts -nonewline $f A\xC0
    flush $f
    seek $f 0
    fconfigure $f -encoding utf-8 -buffering none
} -body {
    set status [catch {read $f} cres copts]
    set d [read $f]
    set d [dict get $copts -result]
    close $f
    binary scan $d H* hd
	lappend res $hd
	lappend res $status
	lappend res $cres
    set hd
	return $res
} -cleanup {
    removeFile io-75.10
} -result 41c0
} -match glob -result {41 1 {error reading "*": illegal byte sequence}}
# The current result returns the orphan byte as byte.
# This may be expected due to special utf-8 handling.

# As utf-8 has a special treatment in multi-byte decoding, also test another
# one.
test io-75.11 {shiftjis encoding error read results in raw bytes} -setup {
    set fn [makeFile {} io-75.11]
    set f [open $fn w+]
    fconfigure $f -encoding binary
    # In shiftjis, \x81 starts a two-byte sequence.
    # But 2nd byte \xFF is not allowed
    puts -nonewline $f A\x81\xFFA
    flush $f
    seek $f 0
    fconfigure $f -encoding shiftjis -buffering none -eofchar "" -translation lf -encodingstrict 1
} -body {
    set status [catch {read $f} cres copts]
    set d [read $f]
    set d [dict get $copts -result]
    binary scan $d H* hd
    lappend hd [catch {set d [read $f]} msg]
    lappend hd $msg
    lappend hd $status
    lappend hd $cres
} -cleanup {
    close $f
    removeFile io-75.11
} -match glob -result {41 1 {error reading "*": illegal byte sequence}}

test io-75.12 {invalid utf-8 encoding read is ignored} -setup {
test io-75.12 {invalid utf-8 encoding read returns an error} -setup {
	set res {}
    set fn [makeFile {} io-75.12]
    set f [open $fn w+]
    fconfigure $f -encoding binary
    puts -nonewline $f A\x81
    flush $f
    seek $f 0
    fconfigure $f -encoding utf-8 -buffering none -eofchar {} -translation lf
} -body {
    set status [catch {read $f} cres copts]
    set d [dict get $copts -result]
    close $f
    binary scan $d H* hd
	lappend res $hd $status $cres
	return $res
} -cleanup {
    removeFile io-75.12
} -match glob -result {41 1 {error reading "*": illegal byte sequence}}
test io-75.12_ignore {invalid utf-8 encoding read is ignored} -setup {
    set fn [makeFile {} io-75.12]
    set f [open $fn w+]
    fconfigure $f -encoding binary
    puts -nonewline $f A\x81
    flush $f
    seek $f 0
    fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf
    fconfigure $f -encoding utf-8 -buffering none -eofchar {} \
		-translation lf -encodingignore 1
} -body {
    set d [read $f]
    close $f
    binary scan $d H* hd
    set hd
} -cleanup {
    removeFile io-75.12
} -result 4181
test io-75.13 {invalid utf-8 encoding read is not ignored (-encodingstrict 1)} -setup {
    set fn [makeFile {} io-75.13]
    set f [open $fn w+]
    fconfigure $f -encoding binary
    # \x81 is invalid in utf-8
    puts -nonewline $f "A\x81"
    flush $f
    seek $f 0
    fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf -encodingstrict 1
} -body {
    set status [catch {read $f} cres copts]
    set d [read $f]
    set d [dict get $copts -result]
    binary scan $d H* hd
    lappend hd [catch {read $f} msg]
    lappend hd $status
    close $f
    lappend hd $msg
    lappend hd $cres
} -cleanup {
    removeFile io-75.13
} -match glob -result {41 1 {error reading "*": illegal byte sequence}}


#test io-75.14 {invalid utf-8 encoding strict gets should not hang} -setup {
#    set fn [makeFile {} io-75.14]