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

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