playframework / playframework/twirl

StringInterpolation not works well with Seq

Open
#347 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
561
Forks
118
Avg merge
1d 15h
Merged PRs (30d)
29

Description

import play.twirl.api.StringInterpolation
val test_seq = Seq(10,20,30)
def test_div(i: Int) = html"<div>$i</div>"
html"""
<ul>
  <li>${test_div(-1)}</li>
  ${test_seq.map(i => <li>{test_div(i)}</li>)}
</ul>
"""

outputs

<ul>
  <li><div>-1</div></li>
  <li>&lt;div&gt;10&lt;/div&gt;</li><li>&lt;div&gt;20&lt;/div&gt;</li><li>&lt;div&gt;30&lt;/div&gt;</li>
</ul>

While I expects

<ul>
  <li><div>-1</div></li>
  <li><div>10</div></li><li><div>20</div></li><li><div>30</div></li>
</ul>

I know I can do this using

val test_seq = Seq(10,20,30)
def test_div(i: Int) = html"<div>$i</div>"
html"""
<ul>
  <li>${test_div(-1)}</li>
  ${test_seq.map(i => html"<li>${test_div(i)}</li>")}
</ul>
"""

but I hope we could have it done without nested quoting

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the StringInterpolation entry point and reproduce the provided Seq interpolation example. Compare the current escaped output with the expected unescaped HTML for mapped template fragments; done means the example works without nested quoting while preserving the existing direct interpolation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.