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

fix($templateRequest): Handle empty templates in cache correctly. #14496

Closed

Conversation

rjamet
Copy link
Contributor

@rjamet rjamet commented Apr 22, 2016

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Bug fix.

What is the current behavior? (You can also link to an open issue here)

Empty templates in $templateCache are not considered as in cache for $templateRequest security purposes, so they trigger $sce checks. Specifically, $templateRequest calls $templateCache.get, but looks for the falsiness of the return value instead of it being defined.

What is the new behavior (if this is a feature change)?

Empty templates in $templateCache are now considered as trusted as any other in $templateCache.

Does this PR introduce a breaking change?

No.

Please check if the PR fulfills these requirements

I'm not sure docs are necessary, as this bug wasn't documented.

Other information:

Fixes #14479.

Fixes angular#14479, where $templateRequest looks for truthiness of $templateCache.get,
while it should look for definedness instead.
@@ -68,8 +68,14 @@ function $TemplateRequestProvider() {
// are included in there. This also makes Angular accept any script
// directive, no matter its name. However, we still need to unwrap trusted
// types.
if (!isString(tpl) || !$templateCache.get(tpl)) {
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't you just change this line to ... || isUndefined($templateCache.get(tpl))... and leave everythng else unchanged ?

Copy link
Contributor Author

@rjamet rjamet Apr 22, 2016

Choose a reason for hiding this comment

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

The reasoning is that people asked for wrong fixes several times, so my original code was probably confusing. I've unrolled the if to accomodate clearer comments, but that can be reverted if you prefer.

Edit : No point making this longer than needed, actually. Reverted to the simpler version.

…check.

Following gkalpak's comments on the PR.
gkalpak pushed a commit that referenced this pull request Apr 25, 2016
Implicitly trust empty templates added to `$templateCache` as is the case for all other templates.

Fixes #14479

Closes #14496
@gkalpak gkalpak closed this in 8576baf Apr 25, 2016
gkalpak pushed a commit that referenced this pull request Apr 25, 2016
Implicitly trust empty templates added to `$templateCache` as is the case for all other templates.

Fixes #14479

Closes #14496
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.

empty template are treated as not exist in templateCache
3 participants