From fa746b2430c6f4e2d34bb93ec7075ec9a4ad2c0e Mon Sep 17 00:00:00 2001 From: dan hodges Date: Sat, 14 Aug 2021 14:12:17 -0500 Subject: [PATCH] enable backtracking on comments, otherwise the parser will error when the comment is the last line in a block. --- cssparse/src/cssparse/CssParser.scala | 2 +- cssparse/test/src/cssparse/CssTests.scala | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cssparse/src/cssparse/CssParser.scala b/cssparse/src/cssparse/CssParser.scala index 617562b6..d0d3c1e2 100644 --- a/cssparse/src/cssparse/CssParser.scala +++ b/cssparse/src/cssparse/CssParser.scala @@ -8,7 +8,7 @@ import fastparse.NoWhitespace._ object CssTokensParser { - def comment[_: P] = P( "/*" ~/ (!"*/" ~ AnyChar).rep ~/ "*/") + def comment[_: P] = P( "/*" ~ (!"*/" ~ AnyChar).rep ~ "*/") def newline[_: P] = P( "\n" | "\r\n" | "\r" | "\f") diff --git a/cssparse/test/src/cssparse/CssTests.scala b/cssparse/test/src/cssparse/CssTests.scala index f705ac2e..3fdcd790 100644 --- a/cssparse/test/src/cssparse/CssTests.scala +++ b/cssparse/test/src/cssparse/CssTests.scala @@ -52,6 +52,7 @@ object CssTests extends TestSuite { | font-family: sans-serif; | -webkit-text-size-adjust: 100%; | -ms-text-size-adjust: 100%; + | /* test comment */ |} | """.stripMargin, CssRulesParser.ruleList(_)) @@ -65,7 +66,7 @@ object CssTests extends TestSuite { Left(Declaration("font-family", Seq(IdentToken("sans-serif")), false)), Left(Declaration("-webkit-text-size-adjust", Seq(PercentageToken("100")), false)), Left(Declaration("-ms-text-size-adjust", Seq(PercentageToken("100")), false))))))), - index2 == 363 + index2 == 384 ) }