| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,11 +22,63 @@ const url = require('url'); | |||
| 22 | 22 | } | |
| 23 | 23 | ||
| 24 | 24 | { | |
| 25 | - assert.throws(() => { | ||
| 26 | - url.pathToFileURL('\\\\exa mple\\share\\file.txt', { windows: true }); | ||
| 27 | - }, { | ||
| 28 | - code: 'ERR_INVALID_URL', | ||
| 29 | - }); | ||
| 25 | + const forbiddenHostnameChars = [ | ||
| 26 | + '\\\\exa mple\\share\\file.txt', | ||
| 27 | + '\\\\host name\\share\\file.txt', // space | ||
| 28 | + '\\\\host@name\\share\\file.txt', // at sign | ||
| 29 | + '\\\\host:name\\share\\file.txt', // colon | ||
| 30 | + '\\\\host[name\\share\\file.txt', // left bracket | ||
| 31 | + '\\\\host]name\\share\\file.txt', // right bracket | ||
| 32 | + ]; | ||
| 33 | + for (const path of forbiddenHostnameChars) { | ||
| 34 | + assert.throws(() => { | ||
| 35 | + url.pathToFileURL(path, { windows: true }); | ||
| 36 | + }, { | ||
| 37 | + code: 'ERR_INVALID_URL', | ||
| 38 | + }, `pathToFileURL('${path}') should throw ERR_INVALID_URL`); | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + { | ||
| 43 | + const hostnameStateTerminatorTestCases = [ | ||
| 44 | + { | ||
| 45 | + path: '\\\\host#name\\share\\file.txt', | ||
| 46 | + expected: 'file://host/share/file.txt', | ||
| 47 | + }, | ||
| 48 | + { | ||
| 49 | + path: '\\\\host?name\\share\\file.txt', | ||
| 50 | + expected: 'file://host/share/file.txt', | ||
| 51 | + }, | ||
| 52 | + { | ||
| 53 | + path: '\\\\host/name\\share\\file.txt', | ||
| 54 | + expected: 'file://host/share/file.txt', | ||
| 55 | + }, | ||
| 56 | + ]; | ||
| 57 | + for (const { path, expected } of hostnameStateTerminatorTestCases) { | ||
| 58 | + const actual = url.pathToFileURL(path, { windows: true }).href; | ||
| 59 | + assert.strictEqual(actual, expected); | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + { | ||
| 64 | + const ignoredHostnameCodePointTestCases = [ | ||
| 65 | + { | ||
| 66 | + path: '\\\\host\nname\\share\\file.txt', | ||
| 67 | + expected: 'file://hostname/share/file.txt', | ||
| 68 | + }, | ||
| 69 | + { | ||
| 70 | + path: '\\\\host\rname\\share\\file.txt', | ||
| 71 | + expected: 'file://hostname/share/file.txt', | ||
| 72 | + }, | ||
| 73 | + { | ||
| 74 | + path: '\\\\host\tname\\share\\file.txt', | ||
| 75 | + expected: 'file://hostname/share/file.txt', | ||
| 76 | + }, | ||
| 77 | + ]; | ||
| 78 | + for (const { path, expected } of ignoredHostnameCodePointTestCases) { | ||
| 79 | + const actual = url.pathToFileURL(path, { windows: true }).href; | ||
| 80 | + assert.strictEqual(actual, expected); | ||
| 81 | + } | ||
| 30 | 82 | } | |
| 31 | 83 | ||
| 32 | 84 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments