Skip to content

Do not duplicate words between property and colon - #49

Merged
ai merged 1 commit into
postcss:mainfrom
wahidrizka:fix-duplicated-words-before-colon
Oct 10, 2026
Merged

ai merged 1 commit into
postcss:mainfrom
wahidrizka:fix-duplicated-words-before-colon

Conversation

@wahidrizka

Copy link
Copy Markdown
Contributor

A word between a property and its colon gets into the output twice:

safeParse('a {\n  font-size\n  color: red;\n  margin-left: 10px;\n}').toString()
// 'a {\n  font-size\n  color: red;color\n  margin-left: 10px;\n}'

Parser#decl() keeps such words in raws.between and calls unknownWord() for them. The safe parser's unknownWord() adds them to this.spaces too, so they also get into the raws.before of the next node or the raws.after of the parent.

It happens while typing a new property above an existing one. Stylelint parses CSS with this parser when fixing (--fix in 16.x, --fix=lax in 17.x) and writes the output back. After stylelint --fix (16.26.1) on the CSS above, Chrome 154 stops applying margin-left, because the copied color and margin-left: 10px read as one invalid declaration.

Now decl() clears this.spaces after super.decl(). init() empties it when the declaration starts, so only this copy is there. I added a toString() check to the fixes 2 properties in safe mode test. It fails on main with a { color one: white;one one }. pnpm test passes.

Parser#decl() keeps the words between the property and the colon in
raws.between and calls unknownWord() for them. The safe parser's
unknownWord() added them to the spaces before the next node too, so
the output had them twice.
@ai
ai merged commit 79cb64d into postcss:main Oct 10, 2026
5 checks passed
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.

2 participants