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

server-islands: only encode ETAGO delimiter + opening HTML comment syntax #11513

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kurtextrem
Copy link
Contributor

@kurtextrem kurtextrem commented Jul 20, 2024

Changes

As per https://mathiasbynens.be/notes/etago, to make JSON safe inside a <script> literal, you need to only encode end-open tag (ETAGO) delimiters and <!--. Thus, we can avoid some work. I've also hoisted the regexps so that we only initialize them once.

Regarding the removal of 0x2029 and 0x2028 added in #11508, to me it does not seem security related to escape those, jsesc notes:

avoid errors when passing JSON-formatted data (which may contain U+2028 LINE SEPARATOR, U+2029 PARAGRAPH SEPARATOR, or lone surrogates) to a JavaScript parser or an UTF-8 encoder.

Which does not seem relevant in the server-islands case. Did I miss anything here?

Testing

I used the following snippet by @ascorbic:
image

Docs

Only a small perf related change, so no further docs needed.

Copy link

changeset-bot bot commented Jul 20, 2024

🦋 Changeset detected

Latest commit: 87aa1f6

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 20, 2024
@matthewp
Copy link
Contributor

Thanks @kurtextrem! Would you mind adding a test for this? You can add one here: https://github.com/withastro/astro/blob/main/packages/astro/test/server-islands.test.js (see the fixtures being used). The last PR was a hot-fix so a test didn't get added for urgency but now since the problem is fixed it would be good to have a test to prevent regressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants