From 9422c03a3daa81ced66c64597914ee7a6a99c1cf Mon Sep 17 00:00:00 2001 From: Lars den Bakker Date: Wed, 17 Jul 2019 14:34:43 -0700 Subject: [PATCH] fix importing modules with path segments (#30) --- src/common.js | 2 ++ test/browser-modules.js | 6 ++++++ test/fixtures/es-modules/query-param-a.js | 3 +++ test/fixtures/es-modules/query-param-b.js | 1 + 4 files changed, 12 insertions(+) create mode 100644 test/fixtures/es-modules/query-param-a.js create mode 100644 test/fixtures/es-modules/query-param-b.js diff --git a/src/common.js b/src/common.js index 97cd472a..07b7817e 100755 --- a/src/common.js +++ b/src/common.js @@ -25,6 +25,8 @@ if (typeof document !== 'undefined') { const backslashRegEx = /\\/g; export function resolveIfNotPlainOrUrl (relUrl, parentUrl) { + // strip off any trailing query params or hashes + parentUrl = parentUrl && parentUrl.split('#')[0].split('?')[0]; if (relUrl.indexOf('\\') !== -1) relUrl = relUrl.replace(backslashRegEx, '/'); // protocol-relative diff --git a/test/browser-modules.js b/test/browser-modules.js index 5903e2e8..de26fc0b 100755 --- a/test/browser-modules.js +++ b/test/browser-modules.js @@ -112,6 +112,12 @@ suite('Basic loading tests', () => { assert(m); assert.equal(m.asdf, 'asdf'); }); + + test('Should import a module with query parameters with path segments', async function () { + var m = await importShim('./fixtures/es-modules/query-param-a.js?foo=/foo/bar/'); + assert(m); + assert.equal(m.a, 'ab'); + }); }); suite('Circular dependencies', function() { diff --git a/test/fixtures/es-modules/query-param-a.js b/test/fixtures/es-modules/query-param-a.js new file mode 100644 index 00000000..b33b1348 --- /dev/null +++ b/test/fixtures/es-modules/query-param-a.js @@ -0,0 +1,3 @@ +import { b } from './query-param-b.js'; + +export const a = 'a' + b; \ No newline at end of file diff --git a/test/fixtures/es-modules/query-param-b.js b/test/fixtures/es-modules/query-param-b.js new file mode 100644 index 00000000..fe32ab76 --- /dev/null +++ b/test/fixtures/es-modules/query-param-b.js @@ -0,0 +1 @@ +export const b = 'b'; \ No newline at end of file