Skip to content

fix: strip BOM character from templates #13548

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

Merged
merged 5 commits into from
Oct 10, 2024
Merged

fix: strip BOM character from templates #13548

merged 5 commits into from
Oct 10, 2024

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Oct 9, 2024

Fixes #13519.

Copy link

changeset-bot bot commented Oct 9, 2024

🦋 Changeset detected

Latest commit: bb698f4

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

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

@@ -0,0 +1 @@
<div>&#xFEFF;</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BOM characters can only appear at the very beginning of a file. I don't think we need the logic as presented here, we should just look at the very first charcode and remove it if it's a BOM

Copy link
Contributor Author

@trueadm trueadm Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that but I couldn't get a test case that emulated it. :/ Feel free to try if you have an approach that can work.

Also FWIW BOM characters can appear in other places too – we strip them out of the contentEditable with Lexical as they play havoc with text selection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isn't it a bug if someone has a BOM character not at the start? Not sure we should handle that / slow down our parser for finding these things. Also, AFAIK a BOM character can also be the start of a valid character sequence that means something completely different.

I think it's ok to not have a test for this, as long as there's a small comment explaining what the code does.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the PR to strip BOM once at the start, added a test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@dummdidumm dummdidumm merged commit d220edd into main Oct 10, 2024
9 checks passed
@dummdidumm dummdidumm deleted the strip-bom-char branch October 10, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Svelte 4 > 5 - Whitespaces are rendered where there are none (&#xFEFFF;)
2 participants