Skip to content

Commit a176780

Browse files
committed
Revert "fs: convert to string if input path is buffer"
This reverts commit f7175b0.
1 parent f7175b0 commit a176780

File tree

7 files changed

+22
-30
lines changed

7 files changed

+22
-30
lines changed

lib/fs.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const {
8383
FSReqCallback,
8484
statValues,
8585
} = binding;
86-
const { toPathIfFileURLOrBuffer } = require('internal/url');
86+
const { toPathIfFileURL } = require('internal/url');
8787
const {
8888
customPromisifyArgs: kCustomPromisifyArgsSymbol,
8989
getLazy,
@@ -1765,7 +1765,7 @@ function symlink(target, path, type, callback) {
17651765
callback(new ERR_ACCESS_DENIED('relative symbolic link target'));
17661766
return;
17671767
}
1768-
} else if (typeof target !== 'string' || !isAbsolute(toPathIfFileURLOrBuffer(target))) {
1768+
} else if (typeof target !== 'string' || !isAbsolute(toPathIfFileURL(target))) {
17691769
callback(new ERR_ACCESS_DENIED('relative symbolic link target'));
17701770
return;
17711771
}
@@ -1839,7 +1839,7 @@ function symlinkSync(target, path, type) {
18391839
if (!isAbsolute(BufferToString(target))) {
18401840
throw new ERR_ACCESS_DENIED('relative symbolic link target');
18411841
}
1842-
} else if (typeof target !== 'string' || !isAbsolute(toPathIfFileURLOrBuffer(target))) {
1842+
} else if (typeof target !== 'string' || !isAbsolute(toPathIfFileURL(target))) {
18431843
throw new ERR_ACCESS_DENIED('relative symbolic link target');
18441844
}
18451845
}
@@ -2670,7 +2670,7 @@ if (isWindows) {
26702670
*/
26712671
function realpathSync(p, options) {
26722672
options = getOptions(options);
2673-
p = toPathIfFileURLOrBuffer(p);
2673+
p = toPathIfFileURL(p);
26742674
if (typeof p !== 'string') {
26752675
p += '';
26762676
}
@@ -2830,7 +2830,7 @@ function realpath(p, options, callback) {
28302830
validateFunction(callback, 'cb');
28312831
}
28322832
options = getOptions(options);
2833-
p = toPathIfFileURLOrBuffer(p);
2833+
p = toPathIfFileURL(p);
28342834

28352835
if (typeof p !== 'string') {
28362836
p += '';

lib/internal/fs/glob.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const {
3838
hideStackFrames,
3939
} = require('internal/errors');
4040
const assert = require('internal/assert');
41-
const { toPathIfFileURLOrBuffer } = require('internal/url');
41+
const { toPathIfFileURL } = require('internal/url');
4242

4343
let minimatch;
4444
function lazyMinimatch() {
@@ -269,7 +269,7 @@ class Glob {
269269
constructor(pattern, options = kEmptyObject) {
270270
validateObject(options, 'options');
271271
const { exclude, cwd, withFileTypes } = options;
272-
this.#root = toPathIfFileURLOrBuffer(cwd) ?? '.';
272+
this.#root = toPathIfFileURL(cwd) ?? '.';
273273
this.#withFileTypes = !!withFileTypes;
274274
if (exclude != null) {
275275
validateStringArrayOrFunction(exclude, 'options.exclude');

lib/internal/fs/promises.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const {
8989
} = require('internal/validators');
9090
const pathModule = require('path');
9191
const { isAbsolute } = pathModule;
92-
const { toPathIfFileURLOrBuffer } = require('internal/url');
92+
const { toPathIfFileURL } = require('internal/url');
9393
const {
9494
getLazy,
9595
kEmptyObject,
@@ -997,7 +997,7 @@ async function symlink(target, path, type) {
997997
if (!isAbsolute(BufferToString(target))) {
998998
throw new ERR_ACCESS_DENIED('relative symbolic link target');
999999
}
1000-
} else if (typeof target !== 'string' || !isAbsolute(toPathIfFileURLOrBuffer(target))) {
1000+
} else if (typeof target !== 'string' || !isAbsolute(toPathIfFileURL(target))) {
10011001
throw new ERR_ACCESS_DENIED('relative symbolic link target');
10021002
}
10031003
}

lib/internal/fs/streams.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const {
3838
validatePath,
3939
} = require('internal/fs/utils');
4040
const { Readable, Writable, finished } = require('stream');
41-
const { toPathIfFileURLOrBuffer } = require('internal/url');
41+
const { toPathIfFileURL } = require('internal/url');
4242
const kIoDone = Symbol('kIoDone');
4343
const kIsPerformingIO = Symbol('kIsPerformingIO');
4444

@@ -178,7 +178,7 @@ function ReadStream(path, options) {
178178
validateFunction(this[kFs].open, 'options.fs.open');
179179

180180
// Path will be ignored when fd is specified, so it can be falsy
181-
this.path = toPathIfFileURLOrBuffer(path);
181+
this.path = toPathIfFileURL(path);
182182
this.flags = options.flags === undefined ? 'r' : options.flags;
183183
this.mode = options.mode === undefined ? 0o666 : options.mode;
184184

@@ -330,7 +330,7 @@ function WriteStream(path, options) {
330330
validateFunction(this[kFs].open, 'options.fs.open');
331331

332332
// Path will be ignored when fd is specified, so it can be falsy
333-
this.path = toPathIfFileURLOrBuffer(path);
333+
this.path = toPathIfFileURL(path);
334334
this.flags = options.flags === undefined ? 'w' : options.flags;
335335
this.mode = options.mode === undefined ? 0o666 : options.mode;
336336

lib/internal/fs/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const {
5050
deprecate,
5151
isWindows,
5252
} = require('internal/util');
53-
const { toPathIfFileURLOrBuffer } = require('internal/url');
53+
const { toPathIfFileURL } = require('internal/url');
5454
const {
5555
validateAbortSignal,
5656
validateBoolean,
@@ -719,8 +719,8 @@ const validatePath = hideStackFrames((path, propName = 'path') => {
719719
);
720720
});
721721

722-
const getValidatedPath = hideStackFrames((fileURLOrPathOrBuffer, propName = 'path') => {
723-
const path = toPathIfFileURLOrBuffer(fileURLOrPathOrBuffer);
722+
const getValidatedPath = hideStackFrames((fileURLOrPath, propName = 'path') => {
723+
const path = toPathIfFileURL(fileURLOrPath);
724724
validatePath(path, propName);
725725
return path;
726726
});

lib/internal/test_runner/mock/mock.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const {
3636
fileURLToPath,
3737
isURL,
3838
pathToFileURL,
39-
toPathIfFileURLOrBuffer,
39+
toPathIfFileURL,
4040
URL,
4141
} = require('internal/url');
4242
const {
@@ -210,7 +210,7 @@ class MockModuleContext {
210210
defaultExport,
211211
hasDefaultExport,
212212
namedExports,
213-
caller: toPathIfFileURLOrBuffer(caller),
213+
caller: toPathIfFileURL(caller),
214214
};
215215

216216
sharedState.mockMap.set(baseURL, config);

lib/internal/url.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,18 +1670,10 @@ function pathToFileURL(filepath, options = kEmptyObject) {
16701670
return new URL(resolved, undefined, windows ? kCreateURLFromWindowsPathSymbol : kCreateURLFromPosixPathSymbol);
16711671
}
16721672

1673-
/**
1674-
* @param fileURLOrPathOrBuffer
1675-
* @returns {string}
1676-
*/
1677-
function toPathIfFileURLOrBuffer(fileURLOrPathOrBuffer) {
1678-
if (!isURL(fileURLOrPathOrBuffer)) {
1679-
if (Buffer.isBuffer(fileURLOrPathOrBuffer)) {
1680-
return fileURLOrPathOrBuffer.toString();
1681-
}
1682-
return fileURLOrPathOrBuffer;
1683-
}
1684-
return fileURLToPath(fileURLOrPathOrBuffer);
1673+
function toPathIfFileURL(fileURLOrPath) {
1674+
if (!isURL(fileURLOrPath))
1675+
return fileURLOrPath;
1676+
return fileURLToPath(fileURLOrPath);
16851677
}
16861678

16871679
/**
@@ -1698,7 +1690,7 @@ module.exports = {
16981690
fileURLToPath,
16991691
fileURLToPathBuffer,
17001692
pathToFileURL,
1701-
toPathIfFileURLOrBuffer,
1693+
toPathIfFileURL,
17021694
installObjectURLMethods,
17031695
URL,
17041696
URLPattern,

0 commit comments

Comments
 (0)