Skip to content

Fix braces escaping when template doesn't contains any variable#3099

Merged
Marsup merged 1 commit intohapijs:masterfrom
poupounetjoyeux:master
Mar 23, 2026
Merged

Fix braces escaping when template doesn't contains any variable#3099
Marsup merged 1 commit intohapijs:masterfrom
poupounetjoyeux:master

Conversation

@poupounetjoyeux
Copy link
Copy Markdown
Contributor

@poupounetjoyeux poupounetjoyeux commented Feb 13, 2026

The issue :

When using a message with only escaped braces, it will be returned with special encoded characters

Example :

Having a message defined as follow
{ 'my.message': 'I want to display \\{this_escaped_text\\} to my user' }

Then the final printed message will look like :
I want to display \u0000this_escaped_text\u0001 to my user
Or in console decoding unicodes like this without braces :
I want to display this_escaped_text to my user

What I finally expect is :
I want to display {this_escaped_text} to my user

Identified root cause

Since there is only escaped braces, the template.split function will return the whole text in the unique head part
However, this part is pushed in the processed array without decoding it and then is returned without more process

My proposal

  • Like all other pushed values in the processed array, push the decoded head instead of the encoded one
  • Add a unit test that represent the issue and is failing with the old code, passing witht the new one

# The issue :
When using a message with only escaped braces, it will be returned with special escaped characters

# Example :
Having a message defined as follow
`{ 'my.message': 'I want to display \\{this_escaped_text\\} to my user'}`
Then the final printed message will look like :
`I want to display \u0000this_escaped_text\u0001 to my user`

# Identified root cause
Since there is only escaped braces, the `template.split` function will return the whole text in the unique `head` part
However, this part is pushed in the `processed` array without decoding it and then is returned without more process

# My proposal
As all other pushed value in the `processed` array, push the decoded `head` instead of the encoded value
Add a unit test that represent the issue and is failing with the old code, passing witht the new one
@Marsup Marsup self-assigned this Mar 23, 2026
@Marsup Marsup added the bug Bug or defect label Mar 23, 2026
@Marsup Marsup added this to the 18.1.1 milestone Mar 23, 2026
@Marsup
Copy link
Copy Markdown
Collaborator

Marsup commented Mar 23, 2026

Thanks, nice catch! Not sure why I was so confident in that answer.

@Marsup Marsup merged commit 4323588 into hapijs:master Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bug or defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants