OILS / spec / nul-bytes.test.sh View on Github | oilshell.org

158 lines, 60 significant
1## oils_failures_allowed: 2
2## compare_shells: dash bash mksh zsh ash
3
4#### NUL bytes with echo -e
5case $SH in (dash) exit ;; esac
6
7echo -e '\0-'
8#echo -e '\x00-'
9#echo -e '\000-'
10
11## stdout-repr: "\x00-\n"
12## BUG zsh stdout-repr: "\x00\n"
13## N-I dash stdout-json: ""
14
15#### NUL bytes in printf format
16printf '\0\n'
17## stdout-repr: "\x00\n"
18
19#### NUL bytes in printf value (OSH and zsh agree)
20case $SH in (dash) exit ;; esac
21
22nul=$'\0'
23echo "$nul"
24printf '%s\n' "$nul"
25
26## stdout-repr: "\n\n"
27## OK osh/zsh stdout-repr: "\x00\n\x00\n"
28## N-I dash stdout-json: ""
29
30
31
32#### NUL bytes with echo $'\0' (OSH and zsh agree)
33
34case $SH in (dash) exit ;; esac
35
36# OSH agrees with ZSH -- so you have the ability to print NUL bytes without
37# legacy echo -e
38
39echo $'\0'
40
41## stdout-repr: "\n"
42## OK osh/zsh stdout-repr: "\0\n"
43## N-I dash stdout-json: ""
44
45
46#### NUL bytes and IFS splitting
47case $SH in (dash) exit ;; esac
48
49argv.py $(echo -e '\0')
50argv.py "$(echo -e '\0')"
51argv.py $(echo -e 'a\0b')
52argv.py "$(echo -e 'a\0b')"
53
54## STDOUT:
55[]
56['']
57['ab']
58['ab']
59## END
60## BUG zsh STDOUT:
61['', '']
62['']
63['a', 'b']
64['a']
65## END
66
67## N-I dash STDOUT:
68## END
69
70#### NUL bytes with test -n
71
72case $SH in (dash) exit ;; esac
73
74# zsh is buggy here, weird
75test -n $''
76echo status=$?
77
78test -n $'\0'
79echo status=$?
80
81
82## STDOUT:
83status=1
84status=1
85## END
86## OK osh STDOUT:
87status=1
88status=0
89## END
90## BUG zsh STDOUT:
91status=0
92status=0
93## END
94
95## N-I dash STDOUT:
96## END
97
98
99#### NUL bytes with test -f
100
101case $SH in (dash) exit ;; esac
102
103
104test -f $'\0'
105echo status=$?
106
107touch foo
108test -f $'foo\0'
109echo status=$?
110
111test -f $'foo\0bar'
112echo status=$?
113
114test -f $'foobar'
115echo status=$?
116
117
118## STDOUT:
119status=1
120status=0
121status=0
122status=1
123## END
124
125## OK ash STDOUT:
126status=1
127status=0
128status=1
129status=1
130## END
131
132## N-I dash STDOUT:
133## END
134
135
136#### NUL bytes with ${#s} (OSH and zsh agree)
137
138case $SH in (dash) exit ;; esac
139
140empty=$''
141nul=$'\0'
142
143echo empty=${#empty}
144echo nul=${#nul}
145
146
147## STDOUT:
148empty=0
149nul=0
150## END
151
152## OK osh/zsh STDOUT:
153empty=0
154nul=1
155## END
156
157## N-I dash STDOUT:
158## END