From a419e508040dbf2654b9697ed73e3a7236b9160f Mon Sep 17 00:00:00 2001 From: greymoth <246701683+greymoth-jp@users.noreply.github.com> Date: Tue, 30 Jun 2026 00:03:22 +0900 Subject: [PATCH] fix: parse "/*/" as an unclosed comment The comment branch searches for the closing "*/" with value.indexOf("*/", pos), starting at the same index as the opening "/*". For the input "/*/" that search matches the "*" of the opening delimiter plus the following "/", so the parser reports a closed empty comment and never sets the unclosed flag. On stringify it then emits "/**/", so the round trip is not lossless. "/*/" is an unterminated comment, which postcss core also reports as an unclosed comment. The parser already handles this for other inputs such as "/*x"; only the slash right after the opener slipped through. Start the closing search at pos + 2 so the opening "/*" cannot be matched as its own terminator. --- lib/parse.js | 2 +- test/parse.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index 7d343ca..48d2981 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -103,7 +103,7 @@ module.exports = function (input) { // Comments } else if (code === slash && value.charCodeAt(pos + 1) === star) { - next = value.indexOf("*/", pos); + next = value.indexOf("*/", pos + 2); token = { type: "comment", diff --git a/test/parse.js b/test/parse.js index 22aa393..02a2e59 100644 --- a/test/parse.js +++ b/test/parse.js @@ -1553,6 +1553,19 @@ const tests = [ }, ], }, + { + message: "should not treat the opening slash-star as its own terminator", + fixture: "/*/", + expected: [ + { + type: "comment", + sourceIndex: 0, + sourceEndIndex: 3, + value: "/", + unclosed: true, + }, + ], + }, { message: "should respect escape character", fixture: "Hawaii \\35 -0",