Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ fs.readFileSync = function(path, options) {

// Used by binding.open and friends
function stringToFlags(flag) {
// Only mess with strings
if (typeof flag !== 'string') {
// Return early if it's a number
if (typeof flag === 'number') {
return flag;
}

Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-fs-open-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,18 @@ assert.equal(fs._stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
.forEach(function(flags) {
assert.throws(function() { fs._stringToFlags(flags); });
});

assert.throws(
() => fs._stringToFlags({}),
/Unknown file open flag: \[object Object\]/
);

assert.throws(
() => fs._stringToFlags(true),
/Unknown file open flag: true/
);

assert.throws(
() => fs._stringToFlags(null),
/Unknown file open flag: null/
);