diff --git a/test/webkit/utilities.test.ts b/test/webkit/utilities.test.ts index b9255ca0..e4dc0b9b 100644 --- a/test/webkit/utilities.test.ts +++ b/test/webkit/utilities.test.ts @@ -167,6 +167,7 @@ suite('Utilities', () => { suite('webkitUrlToClientUrl()', () => { const TEST_CLIENT_PATH = 'c:/site/scripts/a.js'; + const TEST_WEBKIT_LOCAL_URL = 'file:///' + TEST_CLIENT_PATH; const TEST_WEBKIT_HTTP_URL = 'http://site.com/page/scripts/a.js'; const TEST_CWD = 'c:/site'; @@ -199,8 +200,16 @@ suite('Utilities', () => { throw new Error('Not found'); }; mockery.registerMock('fs', { statSync }); - const Utilities = require(MODULE_UNDER_TEST); - assert.equal(Utilities.webkitUrlToClientUrl(TEST_CWD, TEST_WEBKIT_HTTP_URL), ''); + assert.equal(Utilities().webkitUrlToClientUrl(TEST_CWD, TEST_WEBKIT_HTTP_URL), ''); + }); + + test('file:/// urls are returned canonicalized', () => { + assert.equal(Utilities().webkitUrlToClientUrl('', TEST_WEBKIT_LOCAL_URL), TEST_CLIENT_PATH); + }); + + test('uri encodings are fixed', () => { + const clientPath = 'c:/project/path with spaces/script.js'; + assert.equal(Utilities().webkitUrlToClientUrl(TEST_CWD, 'file:///' + encodeURI(clientPath)), clientPath); }); }); @@ -276,7 +285,7 @@ suite('Utilities', () => { test('regexp', () => { const description = '/^asdf/g'; - testRemoteObjectToValue({ type: 'object', description, objectId: TEST_OBJ_ID}, description, TEST_OBJ_ID); + testRemoteObjectToValue({ type: 'object', description, objectId: TEST_OBJ_ID }, description, TEST_OBJ_ID); }); test('symbol', () => { @@ -289,10 +298,10 @@ suite('Utilities', () => { testRemoteObjectToValue({ type: 'function', description: '() => {\n var x = 1;\n var y = 1;\n}', objectId: TEST_OBJ_ID }, '() => { … }'); // named fn - testRemoteObjectToValue({ type: 'function', description: 'function asdf() {\n var z = 5;\n}'}, 'function asdf() { … }'); + testRemoteObjectToValue({ type: 'function', description: 'function asdf() {\n var z = 5;\n}' }, 'function asdf() { … }'); // anonymous fn - testRemoteObjectToValue({ type: 'function', description: 'function () {\n var z = 5;\n}'}, 'function () { … }'); + testRemoteObjectToValue({ type: 'function', description: 'function () {\n var z = 5;\n}' }, 'function () { … }'); }); test('undefined', () => { diff --git a/tsconfig.json b/tsconfig.json index 18a9bf71..d2d16803 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,7 @@ "outDir": "out" }, "exclude": [ - "node_modules" + "node_modules", + "testapp/node_modules" ] } diff --git a/typings/other.d.ts b/typings/other.d.ts new file mode 100644 index 00000000..2b1dbd14 --- /dev/null +++ b/typings/other.d.ts @@ -0,0 +1,8 @@ +interface String { + /** + * Returns true if the sequence of elements of searchString converted to a String is the + * same as the corresponding elements of this object (converted to a String) starting at + * position. Otherwise returns false. + */ + startsWith(searchString: string, position?: number): boolean; +} \ No newline at end of file diff --git a/webkit/utilities.ts b/webkit/utilities.ts index 393bae41..a0420d04 100644 --- a/webkit/utilities.ts +++ b/webkit/utilities.ts @@ -201,6 +201,14 @@ export function webkitUrlToClientUrl(cwd: string, url: string): string { return ''; } + url = decodeURI(url); + + // If the url is an absolute path to a file that exists, return it without file:///. + // A remote absolute url (cordova) will still need the logic below. + if (url.startsWith('file:///') && existsSync(url.replace(/^file:\/\/\//, ''))) { + return canonicalizeUrl(url); + } + // If we don't have the client workingDirectory for some reason, don't try to map the url to a client path if (!cwd) { return '';