Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prerender): only match href attribute after whitespace #1530

Merged
merged 2 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ async function runParallel<T>(
await refillQueue();
}

const LINK_REGEX = /href=["']?([^"'>]+)/g;
const LINK_REGEX = /(?<=\s)href=["']?([^"'>]+)/g;

function extractLinks(
html: string,
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/routes/500.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default defineEventHandler((event) => {
throw createError({ statusCode: 500, statusMessage: "Test Error" });
});
3 changes: 3 additions & 0 deletions test/fixture/routes/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export default defineEventHandler((event) => {
${links.map((link) => ` <li><a href="${link}">${link}</a></li>`).join("\n")}
</ul>
<!-- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ac fermentum tortor, vitae semper nisl. Morbi eu ex sed lacus mollis mollis vel nec mi. Aenean tincidunt pretium ligula, at dapibus libero vestibulum vel. Nunc in lorem vitae tortor lacinia cursus. Morbi malesuada nunc vel mi ornare, a iaculis magna molestie. In dictum, ex quis euismod semper, augue diam convallis nisi, vitae ullamcorper urna augue vel metus. Cras risus elit, tempus ac pretium quis, gravida id odio. Curabitur posuere diam vel leo imperdiet porttitor. Cras posuere hendrerit porta. In tellus velit, sagittis et scelerisque ultrices, iaculis ut leo. Proin id nibh blandit, pharetra lorem et, feugiat dui. Morbi hendrerit massa nec mauris aliquet ultrices. -->

/* Bad Link Examples */
<a x-href="/500?x-href">x-href attr</a>
</body>
</html>`;
});