Skip to content

Commit

Permalink
Fix microsoft#30 - Can't map scripts with a space or other %encoded c…
Browse files Browse the repository at this point in the history
…har in the path
  • Loading branch information
roblourens committed Nov 7, 2015
1 parent aee6dd2 commit a5309d3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
19 changes: 14 additions & 5 deletions test/webkit/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"outDir": "out"
},
"exclude": [
"node_modules"
"node_modules",
"testapp/node_modules"
]
}
8 changes: 8 additions & 0 deletions typings/other.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 8 additions & 0 deletions webkit/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down

0 comments on commit a5309d3

Please sign in to comment.