Skip to content

Commit

Permalink
[FIX] fsInterface on Windows: Correctly handle project paths containi…
Browse files Browse the repository at this point in the history
…ng non-ASCII characters

The `slash` module does not convert "extended-length" paths or paths
which contain non-ASCII characters as documented in the modules README:
https://github.com/sindresorhus/slash/blob/7a9158487d8046c13f2de1db7e3734d33bdbb1bd/readme.md#slash-

Since in our case the resulting POSIX paths are only used in our virtual
fs "@ui5/fs", these limitations are not relevent to us.

Therefore we can simply replace any backslashes.
  • Loading branch information
RandomByte committed Dec 18, 2020
1 parent 1281c2c commit 6bb44be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 7 additions & 4 deletions lib/fsInterface.js
@@ -1,3 +1,7 @@
function toPosix(inputPath) {
return inputPath.replace(/\\/g, "/");
}

/**
* Wraps readers to access them through a [Node.js fs]{@link https://nodejs.org/api/fs.html} styled interface.
*
Expand All @@ -12,7 +16,6 @@
* [<code>mkdir</code>]{@link https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback}
*/
module.exports = (reader) => {
const slash = require("slash");
return {
readFile(fsPath, options, callback) {
if (typeof options === "function") {
Expand All @@ -22,7 +25,7 @@ module.exports = (reader) => {
if (typeof options === "string") {
options = {encoding: options};
}
const posixPath = slash(fsPath);
const posixPath = toPosix(fsPath);
reader.byPath(posixPath, {
nodir: false
}).then(function(resource) {
Expand All @@ -47,7 +50,7 @@ module.exports = (reader) => {
}).catch(callback);
},
stat(fsPath, callback) {
const posixPath = slash(fsPath);
const posixPath = toPosix(fsPath);
reader.byPath(posixPath, {
nodir: false
}).then(function(resource) {
Expand All @@ -61,7 +64,7 @@ module.exports = (reader) => {
}).catch(callback);
},
readdir(fsPath, callback) {
let posixPath = slash(fsPath);
let posixPath = toPosix(fsPath);
if (!posixPath.match(/\/$/)) {
// Add trailing slash if not present
posixPath += "/";
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -111,8 +111,7 @@
"micromatch": "^4.0.2",
"minimatch": "^3.0.3",
"pretty-hrtime": "^1.0.3",
"random-int": "^2.0.1",
"slash": "^3.0.0"
"random-int": "^2.0.1"
},
"devDependencies": {
"ava": "^3.14.0",
Expand Down

0 comments on commit 6bb44be

Please sign in to comment.