Open cyberalien opened 7 months ago
Sounds like a good candidate for a PR to me 👍
I'm trying to add this to unit tests, but can't get test to fail. Using this as example: https://github.com/unjs/nitro/pull/1485/files
Only Deno test fails. I'm not sure pretender test is even ran. Any idea what I could be doing wrong?
Added pull request, but without unit test. It works correctly for existing tests.
Changing regex in Nuxt app fixes issue and finds all other routes correctly.
Thanks for report. It is a valid issue. (see https://github.com/unjs/nitro/pull/2105#issuecomment-1907088991 also)
I think as part of a final fix we should switch to an AST parser (https://github.com/unjs/nitro/issues/2113) but also we probably should also make new URL
safer to avoid failing like this during prerendering but instead simply ignore invalid URLs (PR welcome for this!)
Yes, that is the best solution. Thanks!
In the meantime, is there an option to disable crawling links? Search mentions option crawl: false
, but it is for Nuxt 2 and it doesn't seem to exist in version 3.
@cyberalien crawlLinks: false
Environment
Nitro: 2.8.1 Node: 20.5.0
Reproduction
Nuxt demo, run
npm run generate
to trigger error: https://stackblitz.com/edit/github-ktqr8f?file=pages%2Findex.vueDescribe the bug
Nitro contains regex for finding links in HTML: https://github.com/unjs/nitro/blob/7d3ca94f14aa712eaeb0c4f0b8d81b126f2e913b/src/prerender.ts#L360
It attempts to parse HTML that is passed as serialised JSON to element, resulting in exception.
Part of HTML that Nitro parses incorrectly (small chunk to show error):
Can post bigger file if needed, whole page it parses is over 600kb, chunk that regex matches is about 6kb long.
Additional context
Regex for catching links is currently:
In code sample above, it matches
href=\"#flagAd1x10\" transform=\"ma
and match goes on for about 6kb, which is a bug.I think solution is to remove
(?!")
, which covers only one very specific case and change["']?
to["']
, so single or double quote is required.Logs