Do not emit multiple UTF-8 BOM markers - #2136
Open
arronKler wants to merge 1 commit into
Open
Conversation
8.5.24 restored a leading BOM on stringify. Concatenated CSS and documents with several BOM-tagged roots then contained U+FEFF in the middle of the output. Strip every leading BOM on parse, skip stray markers while tokenizing, and emit at most one BOM when stringifying. Fixes postcss#2133
ai
reviewed
Aug 14, 2026
|
|
||
| function nextToken(opts) { | ||
| if (returned.length) return returned.pop() | ||
| skipBom() |
Member
There was a problem hiding this comment.
Why do we need it if we already have this.css.replace(/^[\uFEFF\uFFFE]+/, '')?
De-ASI-INTERFACE
approved these changes
Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
v8.5.24 started restoring a leading BOM on stringify (#2119). That is correct for a single file, but
parse/stringifycould still produce more than one U+FEFF:a{}\uFEFFb{}) re-emitted the mid-file marker as part of the next selectorDocumentof several BOM-tagged roots wrote a BOM before every rootThose extra markers show up in the middle of generated CSS and break the first rule after each one.
Solution
Input, not only the firstStringifier#rootA single leading BOM is still preserved.
parse('\uFEFFa{}').toString()remains\uFEFFa{}.Fixes #2133