Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): handle strings inside bindings that contain binding characters #39826

Closed
wants to merge 4 commits into from

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Nov 24, 2020

Currently the compiler treats something like {{ '{{a}}' }} as a nested binding and throws an error, because it doesn't account for quotes when it looks for binding characters. These changes add a bit of logic to skip over text inside quotes when parsing.

@google-cla google-cla bot added the cla: yes label Nov 24, 2020
@crisbeto crisbeto force-pushed the 39601/interpolation-quoted branch 2 times, most recently from 1e58121 to 13f72e3 Compare November 24, 2020 17:51
@crisbeto crisbeto marked this pull request as ready for review November 24, 2020 18:30
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer area: compiler Issues related to `ngc`, Angular's template compiler compiler: parser target: patch This PR is targeted for the next patch release labels Nov 24, 2020
@ngbot ngbot bot modified the milestone: needsTriage Nov 24, 2020
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

The change looks good, I've just left a few comments.

I think it'd be great if @petebacondarwin can have a look as well, since he did some work in expression parser recently.

Thank you.

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Nice little fix @crisbeto - I agree with @AndrewKushnir's test addition suggestion. I made some suggestions of my own for the tests and the algorithm. Feel free to consider them :-)

packages/compiler/src/expression_parser/parser.ts Outdated Show resolved Hide resolved
packages/compiler/src/expression_parser/parser.ts Outdated Show resolved Hide resolved
@crisbeto
Copy link
Member Author

Thank you for the reviews everybody, all of the should be addressed now.

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note action: presubmit The PR is in need of a google3 presubmit and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 30, 2020
@AndrewKushnir
Copy link
Contributor

Presubmit.

@AndrewKushnir
Copy link
Contributor

AndrewKushnir commented Dec 1, 2020

@crisbeto just a quick update:

  • it looks like there is a merge conflict now, could you please rebase when you get a chance?
  • presubmit indicated a problem with one of the targets (thus adding the "blocked" label for now). The problem seems to be related to a typo in a template, but I need a bit more time to investigate it and probably do a global run to make sure there is no regression in other places.

Will keep this thread updated.

@AndrewKushnir
Copy link
Contributor

Global presubmit.

@jessicajaniuk jessicajaniuk removed the action: merge The PR is ready for merge by the caretaker label Dec 1, 2020
@crisbeto
Copy link
Member Author

crisbeto commented Dec 8, 2020

Thank you for looking into it @AndrewKushnir. I've added logic to handle the two use cases that you mentioned and included some more unit tests. Can we run it through again?

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

I've added logic to handle the two use cases that you mentioned and included some more unit tests. Can we run it through again?

Thanks @crisbeto! I've just added a quick comment on the // case to see if we can add more tests (and whether the way we handle that is correct). Could you please have a look when you get a chance?

@AndrewKushnir
Copy link
Contributor

AndrewKushnir commented Dec 9, 2020

@pullapprove pullapprove bot removed the area: compiler Issues related to `ngc`, Angular's template compiler label Dec 9, 2020
@ngbot ngbot bot removed this from the needsTriage milestone Dec 9, 2020
@AndrewKushnir AndrewKushnir removed action: presubmit The PR is in need of a google3 presubmit state: blocked labels Dec 9, 2020
@AndrewKushnir
Copy link
Contributor

FYI, presubmits went well 👍

Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

LGTM!

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Dec 9, 2020
@AndrewKushnir AndrewKushnir removed the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Dec 9, 2020
alxhub pushed a commit that referenced this pull request Dec 10, 2020
…aracters (#39826)

Currently the compiler treats something like `{{  '{{a}}' }}` as a nested
binding and throws an error, because it doesn't account for quotes
when it looks for binding characters. These changes add a bit of
logic to skip over text inside quotes when parsing.

Fixes #39601.

PR Close #39826
@alxhub alxhub closed this in dc6d40e Dec 10, 2020
zarend pushed a commit to zarend/angular that referenced this pull request Dec 11, 2020
…aracters (angular#39826)

Currently the compiler treats something like `{{  '{{a}}' }}` as a nested
binding and throws an error, because it doesn't account for quotes
when it looks for binding characters. These changes add a bit of
logic to skip over text inside quotes when parsing.

Fixes angular#39601.

PR Close angular#39826
it('should parse interpolation with escaped backslashes', () => {
checkInterpolation(`{{foo.split('\\\\')}}`, `{{ foo.split("\\") }}`);
checkInterpolation(`{{foo.split('\\\\\\\\')}}`, `{{ foo.split("\\\\") }}`);
checkInterpolation(`{{foo.split('\\\\\\\\\\\\')}}`, `{{ foo.split("\\\\\\") }}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

A tip: this code would greatly benefit from String.raw`\no \escaping \here`. See MDN for details.

@pullapprove pullapprove bot added area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime labels Dec 16, 2020
@ngbot ngbot bot modified the milestone: Backlog Dec 16, 2020
crisbeto added a commit to crisbeto/angular that referenced this pull request Dec 26, 2020
…ng in property binding

Currently we check whether a property binding contains an interpolation using a regex so
that we can throw an error. The problem is that the regex doesn't account for quotes
which means that something like `[prop]="'{{ foo }}'"` will be considered an error, even
though it's not actually an interpolation.

These changes build on top of the logic from angular#39826 to account for interpolation
characters inside quotes.

Fixes angular#39601.
josephperrott pushed a commit that referenced this pull request Jan 5, 2021
…ng in property binding (#40267)

Currently we check whether a property binding contains an interpolation using a regex so
that we can throw an error. The problem is that the regex doesn't account for quotes
which means that something like `[prop]="'{{ foo }}'"` will be considered an error, even
though it's not actually an interpolation.

These changes build on top of the logic from #39826 to account for interpolation
characters inside quotes.

Fixes #39601.

PR Close #40267
josephperrott pushed a commit that referenced this pull request Jan 5, 2021
…ng in property binding (#40267)

Currently we check whether a property binding contains an interpolation using a regex so
that we can throw an error. The problem is that the regex doesn't account for quotes
which means that something like `[prop]="'{{ foo }}'"` will be considered an error, even
though it's not actually an interpolation.

These changes build on top of the logic from #39826 to account for interpolation
characters inside quotes.

Fixes #39601.

PR Close #40267
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime cla: yes compiler: parser risk: medium target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants