1 // Copyright Joyent, Inc. and other Node contributors.
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
22 var common = require('../common');
23 var assert = require('assert');
24 var fs = require('fs');
26 function check(async, sync) {
27 var expected = /Path must be a string without null bytes./;
28 var argsSync = Array.prototype.slice.call(arguments, 2);
29 var argsAsync = argsSync.concat(function(er) {
30 assert(er && er.message.match(expected));
34 assert.throws(function() {
35 console.error(sync.name, argsSync);
36 sync.apply(null, argsSync);
40 async.apply(null, argsAsync);
43 check(fs.appendFile, fs.appendFileSync, 'foo\u0000bar');
44 check(fs.chmod, fs.chmodSync, 'foo\u0000bar', '0644');
45 check(fs.chown, fs.chownSync, 'foo\u0000bar', 12, 34);
46 check(fs.link, fs.linkSync, 'foo\u0000bar', 'foobar');
47 check(fs.link, fs.linkSync, 'foobar', 'foo\u0000bar');
48 check(fs.lstat, fs.lstatSync, 'foo\u0000bar');
49 check(fs.mkdir, fs.mkdirSync, 'foo\u0000bar', '0755');
50 check(fs.open, fs.openSync, 'foo\u0000bar', 'r');
51 check(fs.readFile, fs.readFileSync, 'foo\u0000bar');
52 check(fs.readdir, fs.readdirSync, 'foo\u0000bar');
53 check(fs.readlink, fs.readlinkSync, 'foo\u0000bar');
54 check(fs.realpath, fs.realpathSync, 'foo\u0000bar');
55 check(fs.rename, fs.renameSync, 'foo\u0000bar', 'foobar');
56 check(fs.rename, fs.renameSync, 'foobar', 'foo\u0000bar');
57 check(fs.rmdir, fs.rmdirSync, 'foo\u0000bar');
58 check(fs.stat, fs.statSync, 'foo\u0000bar');
59 check(fs.symlink, fs.symlinkSync, 'foo\u0000bar', 'foobar');
60 check(fs.symlink, fs.symlinkSync, 'foobar', 'foo\u0000bar');
61 check(fs.truncate, fs.truncateSync, 'foo\u0000bar');
62 check(fs.unlink, fs.unlinkSync, 'foo\u0000bar');
63 check(null, fs.unwatchFile, 'foo\u0000bar', assert.fail);
64 check(fs.utimes, fs.utimesSync, 'foo\u0000bar', 0, 0);
65 check(null, fs.watch, 'foo\u0000bar', assert.fail);
66 check(null, fs.watchFile, 'foo\u0000bar', assert.fail);
67 check(fs.writeFile, fs.writeFileSync, 'foo\u0000bar');
69 // an 'error' for exists means that it doesn't exist.
70 // one of many reasons why this file is the absolute worst.
71 fs.exists('foo\u0000bar', function(exists) {
74 assert(!fs.existsSync('foo\u0000bar'));