Skip to content

Commit

Permalink
fix: respect #hash in sources
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Mar 11, 2020
1 parent a17df49 commit 079d623
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 48 deletions.
16 changes: 11 additions & 5 deletions src/plugins/source-plugin.js
Expand Up @@ -516,13 +516,19 @@ export default (options) =>
let offset = 0;

for (const source of sources) {
const { value, startIndex, unquoted } = source;
const uri = parse(value);
const { startIndex, unquoted } = source;
let { value } = source;
const URLObject = parse(value);

if (typeof uri.hash !== 'undefined') {
uri.hash = null;
if (typeof URLObject.hash !== 'undefined') {
const { hash } = URLObject;

source.value = uri.format();
URLObject.hash = null;
source.value = URLObject.format();

if (hash) {
value = value.slice(0, value.length - hash.length);
}
}

const importKey = urlToRequest(
Expand Down
116 changes: 98 additions & 18 deletions test/__snapshots__/attributes-option.test.js.snap

Large diffs are not rendered by default.

36 changes: 30 additions & 6 deletions test/__snapshots__/esModule-option.test.js.snap

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions test/__snapshots__/loader.test.js.snap

Large diffs are not rendered by default.

50 changes: 37 additions & 13 deletions test/__snapshots__/minimize-option.test.js.snap

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions test/__snapshots__/root-option.test.js.snap

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions test/fixtures/simple.html
Expand Up @@ -224,3 +224,11 @@ <h2>An Ordered HTML List</h2>
<img src = ~aliasImageWithSpace />
<img src = "~aliasImageWithSpace" />
<img src = '~aliasImageWithSpace' />

<img src="#hash" />
<img src="javascript:void(0)" />
<img src='image.png#hash' />
<img src=image.png#hash />
<img src=image.png# />
<img srcset="image.png#hash" />
<img srcset="image.png#foo 480w, image.png#bar 800w" sizes="(max-width: 600px) 480px, 800px" src="image.png#baz" alt="Elva dressed as a fairy">

0 comments on commit 079d623

Please sign in to comment.