Diff
Not logged in

Differences From Artifact [5a7c970b77]:

To Artifact [33a3653914]:


1566
1567
1568
1569
1570
1571
1572
1573

1574
1575

1576
1577
1578
1579
1580
1581
1582
1566
1567
1568
1569
1570
1571
1572

1573
1574

1575
1576
1577
1578
1579
1580
1581
1582







-
+

-
+







			set status [catch {read $f} cres copts]
			set in [dict get $copts -result]
			lappend res $in
			lappend res $status $cres
			set res
		} -cleanup {
			catch {close $f}
		} -match glob -result {aaaaaaaaa 1\
		} -match glob -result {{read aaaaaaaaa} 1\
			{error reading "*": illegal byte sequence}\
			{} 1 {error reading "*": illegal byte sequence}}
			{read {}} 1 {error reading "*": illegal byte sequence}}
	}

	foreach variant {default encodingstrict} strict {{} {-encodingstrict 1}} {
		set script [string map [
			list @variant@ $variant @strict@ $strict] $template] 
		uplevel 1 $script
	}
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
9132
9133
9134
9135
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
9132
9133
9134
9135







-
+


















-
+







    # \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]
    set d [dict get $copts -result read]
    binary scan $d H* hd
    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 [dict get $copts -result]
    set d [dict get $copts -result read]
    binary scan $d H* hd
    lappend hd [eof $f]
    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
9212
9213
9214
9215
9216
9217
9218
9219

9220
9221
9222
9223
9224
9225
9226
9212
9213
9214
9215
9216
9217
9218

9219
9220
9221
9222
9223
9224
9225
9226







-
+







    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 [dict get $copts -result]
    set d [dict get $copts -result read]
    close $f
    binary scan $d H* hd
	lappend res $hd
	lappend res $status
	lappend res $cres
	return $res
} -cleanup {
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
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







-
+



















-
+







    # 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 [dict get $copts -result]
    set d [dict get $copts -result read]
    binary scan $d H* hd
    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 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]
    set d [dict get $copts -result read]
    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}}
9295
9296
9297
9298
9299
9300
9301
9302

9303
9304
9305
9306
9307
9308
9309
9295
9296
9297
9298
9299
9300
9301

9302
9303
9304
9305
9306
9307
9308
9309







-
+







    # \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]
    set d [dict get $copts -result read]
    binary scan $d H* hd
    lappend hd $status
    close $f
    lappend hd $cres
} -cleanup {
    removeFile io-75.13
} -match glob -result {41 1 {error reading "*": illegal byte sequence}}
9355
9356
9357
9358
9359
9360
9361
9362

9363
9364
9365
9366
9367
9368
9369
9355
9356
9357
9358
9359
9360
9361

9362
9363
9364
9365
9366
9367
9368
9369







-
+







		lappend res [format %x [scan $char %c]]
	}
    return $res
} -cleanup {
    close $chan
    removeFile io-75.15
} -match glob -result {hello 1 {error reading "*": illegal byte sequence}\
    1 {error reading "*": illegal byte sequence} AB c0 40}
    1 {error reading "*": illegal byte sequence} {read AB} c0 40}

# ### ### ### ######### ######### #########



test io-76.0 {channel modes} -setup {
    set datafile [makeFile {some characters} dummy]