Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Escaped interpolation markers are not unescaped if there are no interpolated expressions in the same text #14196

Open
timbertson opened this issue Mar 8, 2016 · 4 comments · May be fixed by #14199

Comments

@timbertson
Copy link

  • Do you want to request a feature or report a bug?

Bug

  • What is the current behavior?

See http://plnkr.co/edit/b5PYWDpsYAoZ5LcDz6o7

  • the first div correctly turns the escaped interpolation markers back into {{ ... }}
  • the second div doesn't, because there is no interpolation used elsewhere in the element text
  • What is the expected behavior?

Escaped interpolation markers should always be unescaped (after interpolation)

  • What is the motivation / use case for changing the behavior?

Currently it's impossible to escape {{ ... }} and have it always render correctly (without resorting to hacks like always inserting an empty interpolation at the start of each value).

  • Which version of Angular, and which browser and OS does this issue affect? Did this work in previous
    versions of Angular? Please also test with the latest stable and snapshot versions.

I wasn't able to find a nightly link, but looking at the source it hasn't changed recently.

@petebacondarwin
Copy link
Member

@timbertson the latest build (of master) is always available at https://code.angularjs.org/snapshot.

@petebacondarwin
Copy link
Member

Oh and there is a really interesting previous discussion about all of this here: #5601

@petebacondarwin
Copy link
Member

It looks like it is a clearly chosen behaviour. I suspect for performance reasons.
https://github.com/angular/angular.js/blob/master/src/ng/interpolate.js#L197-L202.

The path that fails to unescape these is an optimisation from @jbedard cf83b4f

But he was just reproducing the previous behaviour, which seems that to go back through to 1.3.x

We could do a few things to fix this but I suspect that they would all decrease performance

gkalpak added a commit to gkalpak/angular.js that referenced this issue Mar 8, 2016
Previously, whenever `mustHaveExpression` was true (e.g. when compiling a text nodes),
`$interpolate` would not unescape the escaped interpolation markers if there were no actual
interpolation expressionsin the same string.
This commit fixes the problem, by always unescaping the escaped markers (if any).

Due to always checking for the presence of escaped interpolation markers, there is a slight
performance hit.

Fixes angular#14196
gkalpak added a commit to gkalpak/angular.js that referenced this issue Mar 8, 2016
Previously, whenever `mustHaveExpression` was true (e.g. when compiling a text nodes),
`$interpolate` would not unescape the escaped interpolation markers if there were no actual
interpolation expressionsin the same string.
This commit fixes the problem, by always unescaping the escaped markers (if any).

Due to always checking for the presence of escaped interpolation markers, there is a slight
performance hit.

Fixes angular#14196
gkalpak added a commit to gkalpak/angular.js that referenced this issue Mar 8, 2016
Previously, whenever `mustHaveExpression` was true (e.g. when compiling a text node),
`$interpolate` would not unescape the escaped interpolation markers if there were no actual
interpolation expressionsin the same string.
This commit fixes the problem, by always unescaping the escaped markers (if any).

Due to always checking for the presence of escaped interpolation markers, there is a slight
performance hit.

Fixes angular#14196
gkalpak added a commit to gkalpak/angular.js that referenced this issue Mar 8, 2016
Previously, whenever `mustHaveExpression` was true (e.g. when compiling a text node),
`$interpolate` would not unescape the escaped interpolation markers if there were no actual
interpolation expressions in the same string.
This commit fixes the problem, by always unescaping the escaped markers (if any).

Due to always checking for the presence of escaped interpolation markers, there is a slight
performance hit.

Fixes angular#14196
@gkalpak gkalpak added this to the Backlog milestone Mar 8, 2016
@gkalpak
Copy link
Member

gkalpak commented Mar 8, 2016

Here's my attempt at a fix #14199.

The downsides:

  • It's probably a slight BC (as the previous behavior (even if unintuitive) was documented).
  • There is a small performance hit, because we look for escaped markers in all non-empty strings.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.