Skip to content

Commit 6252a3a

Browse files
LiviaMedeirosCeres6
authored andcommitted
fs: mention URL in NUL character error message
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 6bd6214 commit 6252a3a

File tree

3 files changed

+52
-61
lines changed

3 files changed

+52
-61
lines changed

lib/internal/fs/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ const nullCheck = hideStackFrames((path, propName, throwError = true) => {
376376
const err = new ERR_INVALID_ARG_VALUE(
377377
propName,
378378
path,
379-
'must be a string or Uint8Array without null bytes',
379+
'must be a string, Uint8Array, or URL without null bytes',
380380
);
381381
if (throwError) {
382382
throw err;

test/parallel/test-child-process-reject-null-bytes.js

+51-51
Original file line numberDiff line numberDiff line change
@@ -18,56 +18,56 @@ const {
1818

1919
throws(() => exec(`${process.execPath} ${__filename} AAA BBB\0XXX CCC`, mustNotCall()), {
2020
code: 'ERR_INVALID_ARG_VALUE',
21-
message: /The argument 'command' must be a string without null bytes/
21+
name: 'TypeError',
2222
});
2323

2424
throws(() => exec('BBB\0XXX AAA CCC', mustNotCall()), {
2525
code: 'ERR_INVALID_ARG_VALUE',
26-
message: /The argument 'command' must be a string without null bytes/
26+
name: 'TypeError',
2727
});
2828

2929
throws(() => execSync(`${process.execPath} ${__filename} AAA BBB\0XXX CCC`), {
3030
code: 'ERR_INVALID_ARG_VALUE',
31-
message: /The argument 'command' must be a string without null bytes/
31+
name: 'TypeError',
3232
});
3333

3434
throws(() => execSync('BBB\0XXX AAA CCC'), {
3535
code: 'ERR_INVALID_ARG_VALUE',
36-
message: /The argument 'command' must be a string without null bytes/
36+
name: 'TypeError',
3737
});
3838

3939
// Tests for the 'file' argument
4040

4141
throws(() => spawn('BBB\0XXX'), {
4242
code: 'ERR_INVALID_ARG_VALUE',
43-
message: /The argument 'file' must be a string without null bytes/
43+
name: 'TypeError',
4444
});
4545

4646
throws(() => execFile('BBB\0XXX', mustNotCall()), {
4747
code: 'ERR_INVALID_ARG_VALUE',
48-
message: /The argument 'file' must be a string without null bytes/
48+
name: 'TypeError',
4949
});
5050

5151
throws(() => execFileSync('BBB\0XXX'), {
5252
code: 'ERR_INVALID_ARG_VALUE',
53-
message: /The argument 'file' must be a string without null bytes/
53+
name: 'TypeError',
5454
});
5555

5656
throws(() => spawn('BBB\0XXX'), {
5757
code: 'ERR_INVALID_ARG_VALUE',
58-
message: /The argument 'file' must be a string without null bytes/
58+
name: 'TypeError',
5959
});
6060

6161
throws(() => spawnSync('BBB\0XXX'), {
6262
code: 'ERR_INVALID_ARG_VALUE',
63-
message: /The argument 'file' must be a string without null bytes/
63+
name: 'TypeError',
6464
});
6565

6666
// Tests for the 'modulePath' argument
6767

6868
throws(() => fork('BBB\0XXX'), {
6969
code: 'ERR_INVALID_ARG_VALUE',
70-
message: /The argument 'modulePath' must be a string or Uint8Array without null bytes/
70+
name: 'TypeError',
7171
});
7272

7373
// Tests for the 'args' argument
@@ -77,218 +77,218 @@ throws(() => fork('BBB\0XXX'), {
7777

7878
throws(() => execFile(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC'], mustNotCall()), {
7979
code: 'ERR_INVALID_ARG_VALUE',
80-
message: /The argument 'args\[2\]' must be a string without null bytes/
80+
name: 'TypeError',
8181
});
8282

8383
throws(() => execFileSync(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), {
8484
code: 'ERR_INVALID_ARG_VALUE',
85-
message: /The argument 'args\[2\]' must be a string without null bytes/
85+
name: 'TypeError',
8686
});
8787

8888
throws(() => fork(__filename, ['AAA', 'BBB\0XXX', 'CCC']), {
8989
code: 'ERR_INVALID_ARG_VALUE',
90-
message: /The argument 'args\[2\]' must be a string without null bytes/
90+
name: 'TypeError',
9191
});
9292

9393
throws(() => spawn(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), {
9494
code: 'ERR_INVALID_ARG_VALUE',
95-
message: /The argument 'args\[2\]' must be a string without null bytes/
95+
name: 'TypeError',
9696
});
9797

9898
throws(() => spawnSync(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), {
9999
code: 'ERR_INVALID_ARG_VALUE',
100-
message: /The argument 'args\[2\]' must be a string without null bytes/
100+
name: 'TypeError',
101101
});
102102

103103
// Tests for the 'options.cwd' argument
104104

105105
throws(() => exec(process.execPath, { cwd: 'BBB\0XXX' }, mustNotCall()), {
106106
code: 'ERR_INVALID_ARG_VALUE',
107-
message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/
107+
name: 'TypeError',
108108
});
109109

110110
throws(() => execFile(process.execPath, { cwd: 'BBB\0XXX' }, mustNotCall()), {
111111
code: 'ERR_INVALID_ARG_VALUE',
112-
message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/
112+
name: 'TypeError',
113113
});
114114

115115
throws(() => execFileSync(process.execPath, { cwd: 'BBB\0XXX' }), {
116116
code: 'ERR_INVALID_ARG_VALUE',
117-
message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/
117+
name: 'TypeError',
118118
});
119119

120120
throws(() => execSync(process.execPath, { cwd: 'BBB\0XXX' }), {
121121
code: 'ERR_INVALID_ARG_VALUE',
122-
message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/
122+
name: 'TypeError',
123123
});
124124

125125
throws(() => fork(__filename, { cwd: 'BBB\0XXX' }), {
126126
code: 'ERR_INVALID_ARG_VALUE',
127-
message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/
127+
name: 'TypeError',
128128
});
129129

130130
throws(() => spawn(process.execPath, { cwd: 'BBB\0XXX' }), {
131131
code: 'ERR_INVALID_ARG_VALUE',
132-
message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/
132+
name: 'TypeError',
133133
});
134134

135135
throws(() => spawnSync(process.execPath, { cwd: 'BBB\0XXX' }), {
136136
code: 'ERR_INVALID_ARG_VALUE',
137-
message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/
137+
name: 'TypeError',
138138
});
139139

140140
// Tests for the 'options.argv0' argument
141141

142142
throws(() => exec(process.execPath, { argv0: 'BBB\0XXX' }, mustNotCall()), {
143143
code: 'ERR_INVALID_ARG_VALUE',
144-
message: /The property 'options\.argv0' must be a string without null bytes/
144+
name: 'TypeError',
145145
});
146146

147147
throws(() => execFile(process.execPath, { argv0: 'BBB\0XXX' }, mustNotCall()), {
148148
code: 'ERR_INVALID_ARG_VALUE',
149-
message: /The property 'options\.argv0' must be a string without null bytes/
149+
name: 'TypeError',
150150
});
151151

152152
throws(() => execFileSync(process.execPath, { argv0: 'BBB\0XXX' }), {
153153
code: 'ERR_INVALID_ARG_VALUE',
154-
message: /The property 'options\.argv0' must be a string without null bytes/
154+
name: 'TypeError',
155155
});
156156

157157
throws(() => execSync(process.execPath, { argv0: 'BBB\0XXX' }), {
158158
code: 'ERR_INVALID_ARG_VALUE',
159-
message: /The property 'options\.argv0' must be a string without null bytes/
159+
name: 'TypeError',
160160
});
161161

162162
throws(() => fork(__filename, { argv0: 'BBB\0XXX' }), {
163163
code: 'ERR_INVALID_ARG_VALUE',
164-
message: /The property 'options\.argv0' must be a string without null bytes/
164+
name: 'TypeError',
165165
});
166166

167167
throws(() => spawn(process.execPath, { argv0: 'BBB\0XXX' }), {
168168
code: 'ERR_INVALID_ARG_VALUE',
169-
message: /The property 'options\.argv0' must be a string without null bytes/
169+
name: 'TypeError',
170170
});
171171

172172
throws(() => spawnSync(process.execPath, { argv0: 'BBB\0XXX' }), {
173173
code: 'ERR_INVALID_ARG_VALUE',
174-
message: /The property 'options\.argv0' must be a string without null bytes/
174+
name: 'TypeError',
175175
});
176176

177177
// Tests for the 'options.shell' argument
178178

179179
throws(() => exec(process.execPath, { shell: 'BBB\0XXX' }, mustNotCall()), {
180180
code: 'ERR_INVALID_ARG_VALUE',
181-
message: /The property 'options\.shell' must be a string without null bytes/
181+
name: 'TypeError',
182182
});
183183

184184
throws(() => execFile(process.execPath, { shell: 'BBB\0XXX' }, mustNotCall()), {
185185
code: 'ERR_INVALID_ARG_VALUE',
186-
message: /The property 'options\.shell' must be a string without null bytes/
186+
name: 'TypeError',
187187
});
188188

189189
throws(() => execFileSync(process.execPath, { shell: 'BBB\0XXX' }), {
190190
code: 'ERR_INVALID_ARG_VALUE',
191-
message: /The property 'options\.shell' must be a string without null bytes/
191+
name: 'TypeError',
192192
});
193193

194194
throws(() => execSync(process.execPath, { shell: 'BBB\0XXX' }), {
195195
code: 'ERR_INVALID_ARG_VALUE',
196-
message: /The property 'options\.shell' must be a string without null bytes/
196+
name: 'TypeError',
197197
});
198198

199199
// Not testing fork() because it doesn't accept the shell option (internally it
200200
// explicitly sets shell to false).
201201

202202
throws(() => spawn(process.execPath, { shell: 'BBB\0XXX' }), {
203203
code: 'ERR_INVALID_ARG_VALUE',
204-
message: /The property 'options\.shell' must be a string without null bytes/
204+
name: 'TypeError',
205205
});
206206

207207
throws(() => spawnSync(process.execPath, { shell: 'BBB\0XXX' }), {
208208
code: 'ERR_INVALID_ARG_VALUE',
209-
message: /The property 'options\.shell' must be a string without null bytes/
209+
name: 'TypeError',
210210
});
211211

212212
// Tests for the 'options.env' argument
213213

214214
throws(() => exec(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }, mustNotCall()), {
215215
code: 'ERR_INVALID_ARG_VALUE',
216-
message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/
216+
name: 'TypeError',
217217
});
218218

219219
throws(() => exec(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }, mustNotCall()), {
220220
code: 'ERR_INVALID_ARG_VALUE',
221-
message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/
221+
name: 'TypeError',
222222
});
223223

224224
throws(() => execFile(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }, mustNotCall()), {
225225
code: 'ERR_INVALID_ARG_VALUE',
226-
message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/
226+
name: 'TypeError',
227227
});
228228

229229
throws(() => execFile(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }, mustNotCall()), {
230230
code: 'ERR_INVALID_ARG_VALUE',
231-
message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/
231+
name: 'TypeError',
232232
});
233233

234234
throws(() => execFileSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), {
235235
code: 'ERR_INVALID_ARG_VALUE',
236-
message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/
236+
name: 'TypeError',
237237
});
238238

239239
throws(() => execFileSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), {
240240
code: 'ERR_INVALID_ARG_VALUE',
241-
message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/
241+
name: 'TypeError',
242242
});
243243

244244
throws(() => execSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), {
245245
code: 'ERR_INVALID_ARG_VALUE',
246-
message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/
246+
name: 'TypeError',
247247
});
248248

249249
throws(() => execSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), {
250250
code: 'ERR_INVALID_ARG_VALUE',
251-
message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/
251+
name: 'TypeError',
252252
});
253253

254254
throws(() => fork(__filename, { env: { 'AAA': 'BBB\0XXX' } }), {
255255
code: 'ERR_INVALID_ARG_VALUE',
256-
message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/
256+
name: 'TypeError',
257257
});
258258

259259
throws(() => fork(__filename, { env: { 'BBB\0XXX': 'AAA' } }), {
260260
code: 'ERR_INVALID_ARG_VALUE',
261-
message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/
261+
name: 'TypeError',
262262
});
263263

264264
throws(() => spawn(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), {
265265
code: 'ERR_INVALID_ARG_VALUE',
266-
message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/
266+
name: 'TypeError',
267267
});
268268

269269
throws(() => spawn(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), {
270270
code: 'ERR_INVALID_ARG_VALUE',
271-
message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/
271+
name: 'TypeError',
272272
});
273273

274274
throws(() => spawnSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), {
275275
code: 'ERR_INVALID_ARG_VALUE',
276-
message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/
276+
name: 'TypeError',
277277
});
278278

279279
throws(() => spawnSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), {
280280
code: 'ERR_INVALID_ARG_VALUE',
281-
message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/
281+
name: 'TypeError',
282282
});
283283

284284
// Tests for the 'options.execPath' argument
285285
throws(() => fork(__filename, { execPath: 'BBB\0XXX' }), {
286286
code: 'ERR_INVALID_ARG_VALUE',
287-
message: /The property 'options\.execPath' must be a string without null bytes/
287+
name: 'TypeError',
288288
});
289289

290290
// Tests for the 'options.execArgv' argument
291291
throws(() => fork(__filename, { execArgv: ['AAA', 'BBB\0XXX', 'CCC'] }), {
292292
code: 'ERR_INVALID_ARG_VALUE',
293-
message: /The property 'options\.execArgv\[1\]' must be a string without null bytes/
293+
name: 'TypeError',
294294
});

test/parallel/test-fs-whatwg-url.js

-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const fixtures = require('../common/fixtures');
55
const assert = require('assert');
66
const path = require('path');
77
const fs = require('fs');
8-
const os = require('os');
98

109
function pathToFileURL(p) {
1110
if (!path.isAbsolute(p))
@@ -35,7 +34,6 @@ assert.throws(
3534
{
3635
code: 'ERR_INVALID_URL_SCHEME',
3736
name: 'TypeError',
38-
message: 'The URL must be of scheme file'
3937
});
4038

4139
// pct-encoded characters in the path will be decoded and checked
@@ -49,7 +47,6 @@ if (common.isWindows) {
4947
{
5048
code: 'ERR_INVALID_FILE_URL_PATH',
5149
name: 'TypeError',
52-
message: 'File URL path must not include encoded \\ or / characters'
5350
}
5451
);
5552
});
@@ -60,8 +57,6 @@ if (common.isWindows) {
6057
{
6158
code: 'ERR_INVALID_ARG_VALUE',
6259
name: 'TypeError',
63-
message: 'The argument \'path\' must be a string or Uint8Array without ' +
64-
"null bytes. Received 'c:\\\\tmp\\\\\\x00test'"
6560
}
6661
);
6762
} else {
@@ -74,7 +69,6 @@ if (common.isWindows) {
7469
{
7570
code: 'ERR_INVALID_FILE_URL_PATH',
7671
name: 'TypeError',
77-
message: 'File URL path must not include encoded / characters'
7872
});
7973
});
8074
assert.throws(
@@ -84,7 +78,6 @@ if (common.isWindows) {
8478
{
8579
code: 'ERR_INVALID_FILE_URL_HOST',
8680
name: 'TypeError',
87-
message: `File URL host must be "localhost" or empty on ${os.platform()}`
8881
}
8982
);
9083
assert.throws(
@@ -94,8 +87,6 @@ if (common.isWindows) {
9487
{
9588
code: 'ERR_INVALID_ARG_VALUE',
9689
name: 'TypeError',
97-
message: "The argument 'path' must be a string or Uint8Array without " +
98-
"null bytes. Received '/tmp/\\x00test'"
9990
}
10091
);
10192
}

0 commit comments

Comments
 (0)