Skip to content

Commit

Permalink
[fix] HTML crawl regression (#3677)
Browse files Browse the repository at this point in the history
* revert substr -> substring change - they are not equivalent

* add changeset
  • Loading branch information
Conduitry committed Feb 2, 2022
1 parent 7126607 commit e982472
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-pigs-peel.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix regression in parsing HTML when crawling for pre-rendering
12 changes: 6 additions & 6 deletions packages/kit/src/core/adapt/prerender/crawl.js
Expand Up @@ -25,7 +25,7 @@ export function crawl(html) {
if (html[i + 1] === '!') {
i += 2;

if (html.substring(i, DOCTYPE.length).toUpperCase() === DOCTYPE) {
if (html.substr(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.substring(i, CDATA_OPEN.length) === CDATA_OPEN) {
if (html.substr(i, CDATA_OPEN.length) === CDATA_OPEN) {
i += CDATA_OPEN.length;
while (i < html.length) {
if (html.substring(i, CDATA_CLOSE.length) === CDATA_CLOSE) {
if (html.substr(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.substring(i, COMMENT_OPEN.length) === COMMENT_OPEN) {
if (html.substr(i, COMMENT_OPEN.length) === COMMENT_OPEN) {
i += COMMENT_OPEN.length;
while (i < html.length) {
if (html.substring(i, COMMENT_CLOSE.length) === COMMENT_CLOSE) {
if (html.substr(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.substring(i + 2, tag.length).toUpperCase() === tag
html.substr(i + 2, tag.length).toUpperCase() === tag
) {
continue main;
}
Expand Down

0 comments on commit e982472

Please sign in to comment.