Skip to content

Commit d86a8d2

Browse files
UlisesGasconmcollina
authored andcommitted
fix: keep a colon-first segment behind "./" in relative normalization
1 parent eb483b5 commit d86a8d2

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ uri.normalize('http://example.com/a%2Fb')
8181

8282
Reserved path escapes such as `%2F` and `%2E` are preserved as path data during normalization and comparison.
8383

84-
Dot segments in relative references are removed without changing what the reference resolves to: leading `..` segments that cannot be collapsed are kept, and a relative path is never turned into a root-relative one (`a/../b` → `b`, `../x` → `../x`, `x/..` → `./`).
84+
Dot segments in relative references are removed without changing what the reference resolves to: leading `..` segments that cannot be collapsed are kept, a relative path is never turned into a root-relative one, and a first-segment colon exposed by the removal is kept behind a leading `./` so the reference is not reparsed as a scheme (`a/../b` → `b`, `../x` → `../x`, `x/..` → `./`, `a/../a:b` → `./a:b`).
8585

8686
### Equal
8787

‎lib/utils.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,10 @@ function removeDotSegmentsRelative (path) {
386386
if (trailingDirectory && output[output.length - 1] !== '..') {
387387
output.push('')
388388
}
389-
if (output.length === 0 || output[0] === '') {
389+
if (output.length === 0 || output[0] === '' || output[0].includes(':')) {
390+
// An empty path, a leading empty segment ("//"), or a first segment
391+
// containing ":" (which would be mistaken for a scheme, RFC 3986 section
392+
// 4.2) must stay behind a "." segment so the reference keeps its meaning.
390393
output.unshift('.')
391394
}
392395

0 commit comments

Comments
 (0)