Skip to content

Commit

Permalink
[fix] pre-render crawl parse with value-less attributes (#3668)
Browse files Browse the repository at this point in the history
* use .substring, as .substr is apparently deprecated

* fix parsing of attribute following value-less attribute

* add test

* add changeset
  • Loading branch information
Conduitry committed Feb 1, 2022
1 parent c1f5a13 commit 44a7c81
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-goats-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix parsing during pre-render crawl when there are HTML attributes without a value
14 changes: 8 additions & 6 deletions packages/kit/src/core/adapt/prerender/crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function crawl(html) {
if (html[i + 1] === '!') {
i += 2;

if (html.substr(i, DOCTYPE.length).toUpperCase() === DOCTYPE) {
if (html.substring(i, DOCTYPE.length).toUpperCase() === DOCTYPE) {
i += DOCTYPE.length;
while (i < html.length) {
if (html[i++] === '>') {
Expand All @@ -35,10 +35,10 @@ export function crawl(html) {
}

// skip cdata
if (html.substr(i, CDATA_OPEN.length) === CDATA_OPEN) {
if (html.substring(i, CDATA_OPEN.length) === CDATA_OPEN) {
i += CDATA_OPEN.length;
while (i < html.length) {
if (html.substr(i, CDATA_CLOSE.length) === CDATA_CLOSE) {
if (html.substring(i, CDATA_CLOSE.length) === CDATA_CLOSE) {
i += CDATA_CLOSE.length;
continue main;
}
Expand All @@ -48,10 +48,10 @@ export function crawl(html) {
}

// skip comments
if (html.substr(i, COMMENT_OPEN.length) === COMMENT_OPEN) {
if (html.substring(i, COMMENT_OPEN.length) === COMMENT_OPEN) {
i += COMMENT_OPEN.length;
while (i < html.length) {
if (html.substr(i, COMMENT_CLOSE.length) === COMMENT_CLOSE) {
if (html.substring(i, COMMENT_CLOSE.length) === COMMENT_CLOSE) {
i += COMMENT_CLOSE.length;
continue main;
}
Expand Down Expand Up @@ -79,7 +79,7 @@ export function crawl(html) {
if (
html[i] === '<' &&
html[i + 1] === '/' &&
html.substr(i + 2, tag.length).toUpperCase() === tag
html.substring(i + 2, tag.length).toUpperCase() === tag
) {
continue main;
}
Expand Down Expand Up @@ -175,6 +175,8 @@ export function crawl(html) {
hrefs.push(src);
}
}
} else {
i -= 1;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
<body>
<a href="https://external.com">https://external.com</a>
<a href="/wheee">/wheee</a>
<a sveltekit:prefetch href="/wheee2">/wheee</a>
<a href="/wheee3" sveltekit:prefetch>/wheee</a>
<a href="/wheee4">/wheee</a>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["/styles.css", "/favicon.png", "https://external.com", "/wheee"]
["/styles.css", "/favicon.png", "https://external.com", "/wheee", "/wheee2", "/wheee3", "/wheee4"]

0 comments on commit 44a7c81

Please sign in to comment.