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

fix($compile): prevent inlined JSON values in directive templates from being broken by a wrong replacement of '}}' with the user-defined endSymbol. #6493

Closed
wants to merge 1 commit into from

Conversation

frederic-bonjour
Copy link

Request Type: bug

How to reproduce:

  1. Change the startSymbol and endSymbol in $interpolateProvider.
  2. Put this inside a Directive template:
<div data-context='{"context":{"id":3,"type":"page"}}">

Result: the '}}' at the end of the embedded JSON data gets transformed to the endSymbol defined by the developer.

Component(s): $compile

Impact: small

Complexity: medium

This issue is related to:

Detailed Description:

Other Comments:

Discussion about this in a previous PR: #6453

…m being broken by a wrong replacement of '}}' with the user-defined endSymbol.
@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#6493)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@mary-poppins
Copy link

I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let us know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@frederic-bonjour
Copy link
Author

I've signed as a corporation. I've filled, scanned and emailed the form, as expected.
Company name: Ready Business System (RBS), located in France.

Thanks!

var startSymbol = $interpolate.startSymbol(),
endSymbol = $interpolate.endSymbol(),
denormalizeTemplate = (startSymbol == '{{' || endSymbol == '}}')
? identity
: function denormalizeTemplate(template) {
return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we did it like this instead:

template.replace(/\{\{(.*?)\}\}/g, function(_, expr) {
  return startSymbol + expr + endSymbol;
});

I could be wrong (and probably am slightly off on the syntax here), but I would expect this to work a lot better, and be significantly less code.

@caitp
Copy link
Contributor

caitp commented Oct 16, 2014

@fredericbonjour could you also rebase this? thanks

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this pull request May 13, 2016
…rd interpolation symbols

In order to support third party modules that do not use the same interpolation
symbols as the main app, we implemented denormalization (see dfe9983).

This required that 3rd party modules always used the standad `{{` and `}}`
interpolation symbols, so that we could correctly denormalise them to the
current app's symbols.

The problem with this became apparent when an app template using new symbols
inadvertently contained one of the standard interpolation symbols.

E.g. `<div data-context='{"context":{"id":3,"type":"page"}}">`

The double closing curly braces were being incorrectly denormalised.

This commit fixes this by allowing the compiler to be configured to know
what symbols are being used in templates from a given module.

Now modules can specify that what interpolation symbols they use and the
compiler will denormalize appropriately.

Closes angular#6493
Closes angular#6453
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this pull request May 14, 2016
…rd interpolation symbols

In order to support third party modules that do not use the same interpolation
symbols as the main app, we implemented denormalization (see dfe9983).

This required that 3rd party modules always used the standad `{{` and `}}`
interpolation symbols, so that we could correctly denormalise them to the
current app's symbols.

The problem with this became apparent when an app template using new symbols
inadvertently contained one of the standard interpolation symbols.

E.g. `<div data-context='{"context":{"id":3,"type":"page"}}">`

The double closing curly braces were being incorrectly denormalised.

This commit fixes this by allowing the compiler to be configured to know
what symbols are being used in templates from a given module.

Now modules can specify that what interpolation symbols they use and the
compiler will denormalize appropriately.

Closes angular#6493
Closes angular#6453
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants