Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
consider file path as Buffer and as URL. fixes #886
Browse files Browse the repository at this point in the history
  • Loading branch information
igorklopov committed Apr 11, 2020
1 parent b069daa commit c446a5c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion prelude/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ exports.STORE_STAT = 3;
exports.ALIAS_AS_RELATIVE = 0; // require("./file.js") // file or directory
exports.ALIAS_AS_RESOLVABLE = 1; // require("package")

var hasURL = typeof URL !== 'undefined';

function uppercaseDriveLetter (f) {
if (f.slice(1, 3) !== ':\\') return f;
return f[0].toUpperCase() + f.slice(1);
Expand Down Expand Up @@ -41,7 +43,9 @@ function removeTrailingSlashes (f) {

function normalizePath (f) {
var file = f;
if (!(/^.:$/.test(f))) file = path.normalize(file); // 'c:' -> 'c:.'
if (Buffer.isBuffer(file)) file = file.toString();
if (hasURL && file instanceof URL) file = file.pathname;
if (!(/^.:$/.test(file))) file = path.normalize(file); // 'c:' -> 'c:.'
file = uppercaseDriveLetter(file);
file = removeTrailingSlashes(file);
return file;
Expand Down Expand Up @@ -134,6 +138,8 @@ exports.snapshotify = function (file, slash) {

if (win32) {
exports.insideSnapshot = function insideSnapshot (f) {
if (Buffer.isBuffer(f)) f = f.toString();
if (hasURL && f instanceof URL) f = f.pathname;
if (typeof f !== 'string') return false;
var slice112 = f.slice(1, 12);
if (slice112 === ':\\snapshot\\' ||
Expand All @@ -146,6 +152,8 @@ if (win32) {
};
} else {
exports.insideSnapshot = function insideSnapshot (f) {
if (Buffer.isBuffer(f)) f = f.toString();
if (hasURL && f instanceof URL) f = f.pathname;
if (typeof f !== 'string') return false;
var slice010 = f.slice(0, 10);
if (slice010 === '/snapshot/' ||
Expand Down

0 comments on commit c446a5c

Please sign in to comment.