Conversation
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.
|
No review on this since June. Rather than describe it again, here it is run against The line in question: // lib/parse.js:106
next = value.indexOf("*/", pos);
Parsing six inputs through the current file and through the same file with this PR's change: Three rows move and three do not. A well-formed comment, an empty comment and a plain unterminated The last row is the one with consequences. In The one-character change and its controls: The control matters here because starting the search later could plausibly break the ordinary case, and it does not. One thing I am not claiming: $ gh pr checks 101 --repo postcss/postcss-value-parser
no checks reported on the 'fix-slash-star-comment' branchNothing runs on this branch, so the table above is mine, produced locally against your Happy to rebase, or to take the one-character change directly and close this. No attribution needed. |
valueParser("/*/").toString()returns/**/, so the round trip is not lossless for this input.The comment branch looks for the closing
*/withvalue.indexOf("*/", pos), which starts the search 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 ({ value: "", sourceEndIndex: 3 }) and never sets theunclosedflag. On stringify it then emits/*+""+*/, which is/**/./*/is actually an unterminated comment: after/*the only content is/and there is no closing*/. postcss core agrees and reportsUnclosed commentfor the same input. The parser already handles unterminated comments correctly for other inputs (for example/*xyields{ value: "x", unclosed: true }); only the slash right after the opener slipped through.Starting the closing search at
pos + 2, where the comment body begins, stops the opening/*from being matched as its own terminator./*/now parses to{ value: "/", unclosed: true }and round trips back to/*/. Empty and normal comments are unchanged.Added a parse test for
/*/. The existing suite still passes.