Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fs.scandir): correctly handle the leading slash
- Loading branch information
Showing
4 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as assert from 'assert'; | ||
|
||
import * as common from './common'; | ||
|
||
describe('Readers → Common', () => { | ||
describe('.joinPathSegments', () => { | ||
it('should return concatenated string', () => { | ||
assert.strictEqual(common.joinPathSegments('.', 'a', '/'), './a'); | ||
}); | ||
|
||
it('should return correct string when the first segment ens with the separator symbol', () => { | ||
// Unix | ||
assert.strictEqual(common.joinPathSegments('/', 'a', '/'), '/a'); | ||
assert.strictEqual(common.joinPathSegments('//', 'a', '/'), '//a'); | ||
assert.strictEqual(common.joinPathSegments('/a/', 'b', '/'), '/a/b'); | ||
|
||
// Windows | ||
assert.strictEqual(common.joinPathSegments('C:/', 'Users', '/'), 'C:/Users'); | ||
assert.strictEqual(common.joinPathSegments('C:\\', 'Users', '\\'), 'C:\\Users'); | ||
assert.strictEqual(common.joinPathSegments('//?/C:/', 'Users', '/'), '//?/C:/Users'); | ||
assert.strictEqual(common.joinPathSegments('\\\\?\\C:\\', 'Users', '\\'), '\\\\?\\C:\\Users'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function joinPathSegments(a: string, b: string, separator: string): string { | ||
/** | ||
* The correct handling of cases when the first segment is a root (`/`, `C:/`) or UNC path (`//?/C:/`). | ||
*/ | ||
if (a.endsWith(separator)) { | ||
return a + b; | ||
} | ||
|
||
return a + separator + b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters