| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d35348d commit c18ec09
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,8 +6,10 @@ import { isNode } from './common.js'; | |||
| 6 | 6 | function throwResolveError (relUrl, parentUrl) { | |
| 7 | 7 | throw new RangeError('Unable to resolve "' + relUrl + '" to ' + parentUrl); | |
| 8 | 8 | } | |
| 9 | + var backslashRegEx = /\\/g; | ||
| 9 | 10 | export function resolveIfNotPlain (relUrl, parentUrl) { | |
| 10 | - relUrl = relUrl.trim(); | ||
| 11 | + if (relUrl[0] === ' ' || relUrl[relUrl.length - 1] === ' ') | ||
| 12 | + relUrl = relUrl.trim(); | ||
| 11 | 13 | var parentProtocol = parentUrl && parentUrl.substr(0, parentUrl.indexOf(':') + 1); | |
| 12 | 14 | ||
| 13 | 15 | var firstChar = relUrl[0]; | |
@@ -17,12 +19,16 @@ export function resolveIfNotPlain (relUrl, parentUrl) { | |||
| 17 | 19 | if (firstChar === '/' && secondChar === '/') { | |
| 18 | 20 | if (!parentProtocol) | |
| 19 | 21 | throwResolveError(relUrl, parentUrl); | |
| 22 | + if (relUrl.indexOf('\\') !== -1) | ||
| 23 | + relUrl = relUrl.replace(backslashRegEx, '/'); | ||
| 20 | 24 | return parentProtocol + relUrl; | |
| 21 | 25 | } | |
| 22 | 26 | // relative-url | |
| 23 | 27 | else if (firstChar === '.' && (secondChar === '/' || secondChar === '.' && (relUrl[2] === '/' || relUrl.length === 2 && (relUrl += '/')) || | |
| 24 | 28 | relUrl.length === 1 && (relUrl += '/')) || | |
| 25 | 29 | firstChar === '/') { | |
| 30 | + if (relUrl.indexOf('\\') !== -1) | ||
| 31 | + relUrl = relUrl.replace(backslashRegEx, '/'); | ||
| 26 | 32 | var parentIsPlain = !parentProtocol || parentUrl[parentProtocol.length] !== '/'; | |
| 27 | 33 | ||
| 28 | 34 | // read pathname from parent if a URL | |
@@ -115,7 +121,7 @@ export function resolveIfNotPlain (relUrl, parentUrl) { | |||
| 115 | 121 | if (isNode) { | |
| 116 | 122 | // C:\x becomes file:///c:/x (we don't support C|\x) | |
| 117 | 123 | if (relUrl[1] === ':' && relUrl[2] === '\\' && relUrl[0].match(/[a-z]/i)) | |
| 118 | - return 'file:///' + relUrl.replace(/\\/g, '/'); | ||
| 124 | + return 'file:///' + relUrl.replace(backslashRegEx, '/'); | ||
| 119 | 125 | } | |
| 120 | 126 | return relUrl; | |
| 121 | 127 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,9 @@ describe('Simple normalization tests', function () { | |||
| 8 | 8 | it('Should resolve relative with protocol', function () { | |
| 9 | 9 | assert.equal(resolveIfNotPlain('./x:y', 'https://x.com/y'), 'https://x.com/x:y'); | |
| 10 | 10 | }); | |
| 11 | + it('Should convert \ into /', function () { | ||
| 12 | + assert.equal(resolveIfNotPlain('./a\\b', 'https://x.com/z'), 'https://x.com/a/b') | ||
| 13 | + }); | ||
| 11 | 14 | it('Should resolve windows paths as file:/// URLs', function () { | |
| 12 | 15 | assert.equal(resolveIfNotPlain('c:\\some\\path', 'file:///c:/adsf/asdf'), 'file:///c:/some/path'); | |
| 13 | 16 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments