Skip to content

Commit 079d623

Browse files
fix: respect #hash in sources
1 parent a17df49 commit 079d623

File tree

7 files changed

+214
-48
lines changed

7 files changed

+214
-48
lines changed

src/plugins/source-plugin.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,13 +516,19 @@ export default (options) =>
516516
let offset = 0;
517517

518518
for (const source of sources) {
519-
const { value, startIndex, unquoted } = source;
520-
const uri = parse(value);
519+
const { startIndex, unquoted } = source;
520+
let { value } = source;
521+
const URLObject = parse(value);
521522

522-
if (typeof uri.hash !== 'undefined') {
523-
uri.hash = null;
523+
if (typeof URLObject.hash !== 'undefined') {
524+
const { hash } = URLObject;
524525

525-
source.value = uri.format();
526+
URLObject.hash = null;
527+
source.value = URLObject.format();
528+
529+
if (hash) {
530+
value = value.slice(0, value.length - hash.length);
531+
}
526532
}
527533

528534
const importKey = urlToRequest(

test/__snapshots__/attributes-option.test.js.snap

Lines changed: 98 additions & 18 deletions
Large diffs are not rendered by default.

test/__snapshots__/esModule-option.test.js.snap

Lines changed: 30 additions & 6 deletions
Large diffs are not rendered by default.

test/__snapshots__/loader.test.js.snap

Lines changed: 10 additions & 2 deletions
Large diffs are not rendered by default.

test/__snapshots__/minimize-option.test.js.snap

Lines changed: 37 additions & 13 deletions
Large diffs are not rendered by default.

test/__snapshots__/root-option.test.js.snap

Lines changed: 20 additions & 4 deletions
Large diffs are not rendered by default.

test/fixtures/simple.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,11 @@ <h2>An Ordered HTML List</h2>
224224
<img src = ~aliasImageWithSpace />
225225
<img src = "~aliasImageWithSpace" />
226226
<img src = '~aliasImageWithSpace' />
227+
228+
<img src="#hash" />
229+
<img src="javascript:void(0)" />
230+
<img src='image.png#hash' />
231+
<img src=image.png#hash />
232+
<img src=image.png# />
233+
<img srcset="image.png#hash" />
234+
<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 commit comments

Comments
 (0)