Fossil SCM

fossil-scm / test / unicode-pathnames.test
Blame History Raw 405 lines
1
#
2
# Copyright (c) 2026 D. Richard Hipp
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the Simplified BSD License (also
6
# known as the "2-Clause License" or "FreeBSD License".)
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but without any warranty; without even the implied warranty of
10
# merchantability or fitness for a particular purpose.
11
#
12
# Author contact information:
13
# [email protected]
14
# http://www.hwaci.com/drh/
15
#
16
############################################################################
17
#
18
# Pathnames that differ in letter case, or that write the same
19
# characters with different code points: the Unicode normalization
20
# forms NFC, with one code point for an accented letter, and NFD, with
21
# the letter followed by a combining mark.
22
#
23
# With the case-sensitive setting on, fossil compares pathnames byte
24
# for byte, so each spelling is a different file. With the setting
25
# off, two pathnames are the same file when they are a canonical
26
# caseless match (the Unicode Standard, section 3.13, definition D145):
27
# equal after canonical decomposition and case folding. A file system
28
# that ignores case and normalization has one file for both names.
29
#
30
# The harness classifies the temporary volume once at startup
31
# (::fs_type). This file predicts match, miss, or untestable from
32
# that classification, Fossil argv rewriting, and the rules above.
33
# -assurance selects how many pairs to run: smoke (one per
34
# behavior class), ci (the lists below), or stress (ci plus generated
35
# pairs). Unmet predictions fail the run.
36
#
37
# Case folding maps both the sharp s, U+00DF, and the capital sharp s,
38
# U+1E9E, to the two letters "ss", so by D145 a name with a sharp s and
39
# the same name with "ss" are one file. ext4 with case folding folds
40
# each sharp s to "ss" and has one file for the two names. NTFS and
41
# HFS+ convert each character to one character, and have two files.
42
# Collide tests require two names on disk, so they are skipped when
43
# ::fs_type says this volume has one entry for the pair.
44
#
45
46
require_no_open_checkout
47
48
# Fossil reads the pathnames on its command line, and Tcl reads
49
# fossil's output, in the system encoding.
50
#
51
set upSavedEncoding [encoding system]
52
encoding system utf-8
53
54
set upPredMet 0
55
set upPredUnmet 0
56
57
# Returns NAME with each character outside ASCII written as a Tcl
58
# escape, so that two spellings that look the same can be distinguished.
59
#
60
proc up_escape {name} {
61
set escaped ""
62
foreach char [split $name ""] {
63
scan $char %c code
64
if {$code > 126} {
65
append escaped [format {\u%04x} $code]
66
} else {
67
append escaped $char
68
}
69
}
70
return $escaped
71
}
72
73
# Prints the two spellings of the pair LABEL before the tests of that
74
# pair, each unescaped and with escapes.
75
#
76
proc up_show {label a b} {
77
protOut "unicode-pathnames $label: $a ([up_escape $a]) and\
78
$b ([up_escape $b])"
79
}
80
81
# Returns the hash of the check-in that the last "fossil commit" made.
82
#
83
proc up_new_version {} {
84
regexp {New_Version: ([0-9a-f]+)} $::RESULT -> hash
85
return $hash
86
}
87
88
# Which ::fs_type key governs whether this volume stores A and B as one
89
# directory entry. Case-only pairs use ascii_case; NFC/NFD and
90
# compatibility decompositions use normalization; sharp-s uses sharp_s.
91
#
92
proc up_fs_key {label} {
93
switch -exact -- $label {
94
sharp-s - capital-sharp-s - stress-sharp {
95
return sharp_s
96
}
97
nfd - nfd-case - nfd-dir - marks - kana - arabic - angstrom -
98
hangul - han-compat - devanagari - stress-nfd {
99
return normalization
100
}
101
default {
102
return ascii_case
103
}
104
}
105
}
106
107
# Return 1 when ::fs_type says this volume has one directory entry for
108
# the two spellings of LABEL.
109
#
110
proc up_fs_collides {label} {
111
return [dict get $::fs_type [up_fs_key $label]]
112
}
113
114
# Return 1 when fossil test-echo rewrites B to the checked-in spelling A.
115
#
116
proc up_argv_maps {a b} {
117
fossil test-echo $b
118
return [expr {[string first "argv\[2\] = \[$a\]" $::RESULT] >= 0}]
119
}
120
121
# Record whether ACTUAL equals EXPECTED for prediction NAME.
122
#
123
proc up_expect {name actual expected} {
124
set ok [expr {$actual eq $expected}]
125
if {$ok} {
126
incr ::upPredMet
127
} else {
128
incr ::upPredUnmet
129
}
130
test_eq $name $actual $expected
131
}
132
133
# Each row is a label, the pathname that is checked in, and another
134
# spelling that is a D145 caseless match (or treated as one file in
135
# the header for compatibility pairs).
136
#
137
set upSameAll [list \
138
ascii readme.txt README.TXT \
139
ascii-dir dir/notes.txt DIR/Notes.TXT \
140
latin "\u00e4rger.txt" "\u00c4RGER.TXT" \
141
greek "\u03b1\u03c1\u03c7\u03b5\u03af\u03bf.txt" \
142
"\u0391\u03a1\u03a7\u0395\u038a\u039f.TXT" \
143
cyrillic "\u0444\u0430\u0439\u043b.txt" \
144
"\u0424\u0410\u0419\u041b.TXT" \
145
sigma "\u03bf\u03b4\u03cc\u03c2.txt" \
146
"\u039f\u0394\u038c\u03a3.TXT" \
147
nfd "r\u00e9sum\u00e9.txt" "re\u0301sume\u0301.txt" \
148
nfd-case "cr\u00e8me.txt" "CRE\u0300ME.TXT" \
149
marks "\u1ead.txt" "a\u0323\u0302.txt" \
150
angstrom "\u00e5.txt" "\u212b.TXT" \
151
hangul "\ud55c\uae00.txt" \
152
"\u1112\u1161\u11ab\u1100\u1173\u11af.txt" \
153
nfd-dir "caf\u00e9/menu.txt" "CAFE\u0301/MENU.TXT" \
154
sharp-s "stra\u00dfe.txt" "STRASSE.TXT" \
155
capital-sharp-s "gro\u00df.txt" "GRO\u1e9e.TXT" \
156
han "\u4e2d\u6587.txt" "\u4e2d\u6587.TXT" \
157
han-compat "\u8c48.txt" "\uf900.txt" \
158
kana "\u30ac\u30d1.txt" \
159
"\u30ab\u3099\u30cf\u309a.txt" \
160
fullwidth "\uff46\uff49\uff4c\uff45.txt" \
161
"\uff26\uff29\uff2c\uff25.TXT" \
162
arabic "\u0623\u062d\u0645\u062f.txt" \
163
"\u0627\u0654\u062d\u0645\u062f.txt" \
164
devanagari "\u0915\u093c.txt" "\u0958.txt" \
165
]
166
167
# Each row is a label, the pathname that is checked in, and a pathname
168
# that is a different file with the setting on or off.
169
#
170
set upDifferentAll [list \
171
accent "expos\u00e9.txt" expose.txt \
172
other-mark "\u00e5ngstr.txt" "\u00e4ngstr.txt" \
173
superscript "x\u00b2.txt" x2.txt \
174
han-variant "\u6a94\u6848.txt" "\u6863\u6848.txt" \
175
kana-script "\u304b\u306a.txt" "\u30ab\u30ca.txt" \
176
fullwidth-ascii "\uff41\uff42.txt" ab.txt \
177
]
178
179
set upCollideAll [list \
180
ascii readme.txt README.TXT \
181
latin "\u00e4rger.txt" "\u00c4RGER.TXT" \
182
nfd "r\u00e9sum\u00e9.txt" "re\u0301sume\u0301.txt" \
183
nfd-case "cr\u00e8me.txt" "CRE\u0300ME.TXT" \
184
sharp-s "stra\u00dfe.txt" "STRASSE.TXT" \
185
]
186
187
# Smoke: one pair per behavior class.
188
set upSmokeSame {ascii latin sigma nfd sharp-s han-compat}
189
set upSmokeDifferent {accent}
190
set upSmokeCollide {ascii}
191
192
# Stress-only pairs (not in the ci lists).
193
set upStressSame [list \
194
stress-latin "\u00f6ffentlich.txt" "\u00d6FFENTLICH.TXT" \
195
stress-nfd "na\u00efve.txt" "nai\u0308ve.txt" \
196
stress-sharp "gro\u00dfartig.txt" "GROSSARTIG.TXT" \
197
]
198
set upStressDifferent [list \
199
stress-miss "caf\u00e9.txt" cafe.txt \
200
]
201
set upStressCollide [list \
202
stress-latin "\u00f6ffentlich.txt" "\u00d6FFENTLICH.TXT" \
203
stress-nfd "na\u00efve.txt" "nai\u0308ve.txt" \
204
]
205
206
# Build the pair lists for the current -assurance level.
207
#
208
proc up_select {all smokeLabels} {
209
set level [test_assurance]
210
if {$level eq "smoke"} {
211
set out [list]
212
foreach {label a b} $all {
213
if {$label in $smokeLabels} {
214
lappend out $label $a $b
215
}
216
}
217
return $out
218
}
219
return $all
220
}
221
222
set upSame [up_select $upSameAll $upSmokeSame]
223
set upDifferent [up_select $upDifferentAll $upSmokeDifferent]
224
set upCollide [up_select $upCollideAll $upSmokeCollide]
225
226
if {[test_assurance] eq "stress"} {
227
foreach {label a b} $upStressSame {
228
lappend upSame $label $a $b
229
}
230
foreach {label a b} $upStressDifferent {
231
lappend upDifferent $label $a $b
232
}
233
foreach {label a b} $upStressCollide {
234
lappend upCollide $label $a $b
235
}
236
}
237
238
###############################################################################
239
#
240
# One spelling of each pathname is checked in and on disk. Fossil is
241
# then given the other spelling.
242
#
243
test_setup
244
fossil settings case-sensitive 1
245
246
set upNames [list]
247
foreach {label a b} $upSame {
248
file mkdir [file dirname $a]
249
write_file $a "$label\n"
250
lappend upNames $a
251
}
252
foreach {label a b} $upDifferent {
253
write_file $a "$label\n"
254
lappend upNames $a
255
}
256
fossil add {*}$upNames
257
fossil commit -m "one spelling of each pathname"
258
259
fossil ls
260
test_eq unicode-pathnames-ls [lsort [split [normalize_result] \n]] \
261
[lsort $upNames]
262
263
# upConverted lists pairs whose other spelling fossil rewrites to the
264
# checked-in name when it reads its arguments.
265
#
266
set upConverted [list]
267
foreach {label a b} $upSame {
268
if {[up_argv_maps $a $b]} {
269
lappend upConverted $label
270
}
271
}
272
273
# With the setting on, the other spelling is not a file under
274
# management, unless fossil converts it. Positive: converted pairs
275
# find the file. Negative: unconverted pairs do not.
276
#
277
foreach {label a b} $upSame {
278
up_show $label $a $b
279
set converted [expr {$label in $upConverted}]
280
fossil ls $b
281
up_expect unicode-pathnames-on-$label-ls [normalize_result] \
282
[expr {$converted ? $a : ""}]
283
fossil cat $b {*}[expr {$converted ? "" : "-expectError"}]
284
up_expect unicode-pathnames-on-$label-cat $CODE [expr {!$converted}]
285
}
286
287
# With the setting off, D145 matches must be found by the other
288
# spelling; upDifferent pairs must not.
289
#
290
fossil settings case-sensitive 0
291
292
foreach {label a b} $upSame {
293
up_show $label $a $b
294
fossil ls $b
295
up_expect unicode-pathnames-off-$label-ls [normalize_result] $a
296
fossil cat $b
297
up_expect unicode-pathnames-off-$label-cat-code $CODE 0
298
up_expect unicode-pathnames-off-$label-cat [normalize_result] $label
299
fossil rm --soft -n $b
300
up_expect unicode-pathnames-off-$label-rm [normalize_result] "DELETED $a"
301
}
302
303
foreach {label a b} $upDifferent {
304
up_show $label $a $b
305
fossil ls $b
306
up_expect unicode-pathnames-off-$label-ls [normalize_result] ""
307
fossil cat $b -expectError
308
up_expect unicode-pathnames-off-$label-cat $CODE 1
309
fossil rm --soft -n $b
310
up_expect unicode-pathnames-off-$label-rm [normalize_result] ""
311
}
312
313
# A file on disk under the other spelling is not an extra file, and
314
# "fossil add" does not add it. Needs a volume that stores two names.
315
#
316
set upOneFile [list]
317
foreach {label a b} $upSame {
318
up_show $label $a $b
319
if {[up_fs_collides $label] || $label in $upConverted} {
320
lappend upOneFile $label
321
continue
322
}
323
# Confirm the working tree still has two distinct entries.
324
if {[file exists $b]} {
325
lappend upOneFile $label
326
continue
327
}
328
file mkdir [file dirname $b]
329
write_file $b "other spelling\n"
330
fossil extras
331
up_expect unicode-pathnames-off-$label-extras [normalize_result] ""
332
fossil add $b
333
fossil changes
334
up_expect unicode-pathnames-off-$label-add [normalize_result] ""
335
fossil revert
336
file delete $b
337
if {[file dirname $b] ne "."} {
338
catch {file delete [file dirname $b]}
339
}
340
}
341
if {[llength $upOneFile] > 0} {
342
test_skip_part "extras and add tests of [join $upOneFile {, }]:\
343
filesystem type or argv rewriting has one name for both spellings\
344
(fs_type: $::fs_type)"
345
}
346
347
###############################################################################
348
#
349
# A version made with the setting on has both spellings of a pathname.
350
# With the setting off, fossil must refuse to commit from a check-out of
351
# that version and refuse to update to it, because a file system that
352
# has one file for both names would give both the same content.
353
#
354
set upOneFile [list]
355
foreach {label a b} $upCollide {
356
up_show $label $a $b
357
test_setup
358
fossil settings case-sensitive 1
359
write_file $a "first spelling\n"
360
write_file plain.txt "plain\n"
361
fossil add $a plain.txt
362
fossil commit -m "first spelling"
363
set upFirst [up_new_version]
364
set converted [up_argv_maps $a $b]
365
if {$converted} {
366
lappend upConverted $label
367
}
368
if {[up_fs_collides $label] || $converted || [file exists $b]} {
369
lappend upOneFile $label
370
continue
371
}
372
write_file $b "second spelling\n"
373
fossil add $b
374
fossil commit -m "second spelling"
375
set upBoth [up_new_version]
376
377
fossil settings case-sensitive 0
378
write_file plain.txt "edited\n"
379
fossil commit -m "edit plain.txt" -expectError
380
up_expect unicode-pathnames-collide-$label-commit $CODE 1
381
382
fossil settings case-sensitive 1
383
fossil revert
384
fossil update $upFirst
385
fossil settings case-sensitive 0
386
fossil update $upBoth -expectError
387
up_expect unicode-pathnames-collide-$label-update $CODE 1
388
up_expect unicode-pathnames-collide-$label-update-file \
389
[file exists $b] 0
390
}
391
if {[llength $upOneFile] > 0} {
392
test_skip_part "commit and update tests of [join $upOneFile {, }]:\
393
filesystem type or argv rewriting has one name for both spellings\
394
(fs_type: $::fs_type)"
395
}
396
397
###############################################################################
398
399
protOut "***** unicode-pathnames predictions:\
400
met=$upPredMet unmet=$upPredUnmet"
401
test unicode-pathnames-predictions-met {$upPredUnmet == 0}
402
403
encoding system $upSavedEncoding
404
test_cleanup
405

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button