Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Export crawling with missing/empty hrefs #602

Closed
Conduitry opened this issue Mar 11, 2019 · 1 comment · Fixed by #603
Closed

Export crawling with missing/empty hrefs #602

Conduitry opened this issue Mar 11, 2019 · 1 comment · Fixed by #603

Comments

@Conduitry
Copy link
Member

sapper export will crash in certain situations involving missing or empty hrefs on links.

function get_href(attrs: string) {
	const match = /href\s*=\s*(?:"(.*?)"|'(.+?)'|([^\s>]+))/.exec(attrs);
	return match[1] || match[2] || match[3];
}

If an <a> is missing an href altogether, this will crash. If it has href="" it's fine and will return an empty string, but if it has href='' it will return an incorrect string including the quotes (because '(.+?)' refuses to match the pattern, and so it falls back to the third option). I think<a href=> or <a href= > would also fail, but I'm not actually sure what the HTML spec says about that.

@Conduitry
Copy link
Member Author

Conduitry commented Mar 11, 2019

Currently proposed fix: Change the +s to *s in the regex so that it will match empty hrefs, and also check that match is not null (and return null in that case) before trying to subscript it.

Rich-Harris added a commit that referenced this issue Apr 27, 2019
fix handling of empty hrefs during export
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant