Skip to content

Commit

Permalink
Fix parenthesis parsing for args block (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
octonato authored Jul 11, 2019
1 parent 8b0dce7 commit 8adb6af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions compiler/src/test/resources/blockWithNestedTuple.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@(args: Seq[(String, String)])

@args.zipWithIndex.map { case ((k, v), index) =>
@k => @v
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ class CompilerSpec extends WordSpec with MustMatchers {
hello.static(args).toString.trim must be("the-key => the-value")
}

"compile successfully (block with nested tuples)" in {
val helper = newCompilerHelper
val hello = helper.compile[(Seq[(String, String)] => Html)]("blockWithNestedTuple.scala.html", "html.blockWithNestedTuple")

val args = Seq[(String, String)](
"the-key" -> "the-value"
)
hello.static(args).toString.trim must be("the-key => the-value")
}

}

object Helper {
Expand Down
3 changes: 1 addition & 2 deletions parser/src/main/scala/play/twirl/parser/TwirlParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,8 @@ class TwirlParser(val shouldParseInclusiveDot: Boolean) {

val startsWithParenthesis = result.trim.startsWith("(") || result.trim.stripPrefix("case").trim.startsWith("(")
val endsWithParenthesis = result.stripSuffix("=>").trim.endsWith(")")
val exactOneOpenParenthesis = result.count(_ == '(') == 1

noContainsOpenParenthesis || (startsWithParenthesis && endsWithParenthesis && exactOneOpenParenthesis)
noContainsOpenParenthesis || (startsWithParenthesis && endsWithParenthesis)
}

val p = input.offset()
Expand Down

0 comments on commit 8adb6af

Please sign in to comment.