This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix($parse): fix CSP nested property evaluation, and issue that prevente... #5592
Closed
Closed
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
339fc96
fix($parse): fix CSP nested property evaluation, and issue that preve…
dozingcat 5177a62
fix($parse): fix CSP nested property evaluation, and issue that preve…
dozingcat e1d7a5f
fix($parse): fix CSP nested property evaluation, and issue that preve…
dozingcat 3a126a9
fix($parse): fix CSP nested property evaluation, and issue that preve…
dozingcat 6f991b7
fix($parse): fix CSP nested property evaluation, and issue that preve…
dozingcat c4fd978
tests
dozingcat ba7fce5
fix($parse): fix CSP nested property evaluation, and issue that preve…
dozingcat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -894,16 +894,16 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { | |
if (pathVal == null) return pathVal; | ||
pathVal = pathVal[key0]; | ||
|
||
if (pathVal == null) return key1 ? undefined : pathVal; | ||
if (pathVal == null || !key1) return key1 ? undefined : pathVal; | ||
pathVal = pathVal[key1]; | ||
|
||
if (pathVal == null) return key2 ? undefined : pathVal; | ||
if (pathVal == null || !key2) return key2 ? undefined : pathVal; | ||
pathVal = pathVal[key2]; | ||
|
||
if (pathVal == null) return key3 ? undefined : pathVal; | ||
if (pathVal == null || !key3) return key3 ? undefined : pathVal; | ||
pathVal = pathVal[key3]; | ||
|
||
if (pathVal == null) return key4 ? undefined : pathVal; | ||
if (pathVal == null || !key4) return key4 ? undefined : pathVal; | ||
pathVal = pathVal[key4]; | ||
|
||
return pathVal; | ||
|
@@ -924,7 +924,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { | |
} | ||
pathVal = pathVal.$$v; | ||
} | ||
if (pathVal == null) return key1 ? undefined : pathVal; | ||
if (pathVal == null || !key1) return key1 ? undefined : pathVal; | ||
|
||
pathVal = pathVal[key1]; | ||
if (pathVal && pathVal.then) { | ||
|
@@ -936,7 +936,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { | |
} | ||
pathVal = pathVal.$$v; | ||
} | ||
if (pathVal == null) return key2 ? undefined : pathVal; | ||
if (pathVal == null || !key2) return key2 ? undefined : pathVal; | ||
|
||
pathVal = pathVal[key2]; | ||
if (pathVal && pathVal.then) { | ||
|
@@ -948,7 +948,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { | |
} | ||
pathVal = pathVal.$$v; | ||
} | ||
if (pathVal == null) return key3 ? undefined : pathVal; | ||
if (pathVal == null || !key3) return key3 ? undefined : pathVal; | ||
|
||
pathVal = pathVal[key3]; | ||
if (pathVal && pathVal.then) { | ||
|
@@ -960,7 +960,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { | |
} | ||
pathVal = pathVal.$$v; | ||
} | ||
if (pathVal == null) return key4 ? undefined : pathVal; | ||
if (pathVal == null || !key4) return key4 ? undefined : pathVal; | ||
|
||
pathVal = pathVal[key4]; | ||
if (pathVal && pathVal.then) { | ||
|
@@ -1218,8 +1218,6 @@ function $ParseProvider() { | |
|
||
|
||
this.$get = ['$filter', '$sniffer', '$log', function($filter, $sniffer, $log) { | ||
$parseOptions.csp = $sniffer.csp; | ||
|
||
promiseWarning = function promiseWarningFn(fullExp) { | ||
if (!$parseOptions.logPromiseWarnings || promiseWarningCache.hasOwnProperty(fullExp)) return; | ||
promiseWarningCache[fullExp] = true; | ||
|
@@ -1237,6 +1235,9 @@ function $ParseProvider() { | |
return cache[exp]; | ||
} | ||
|
||
// The csp option has to be set here because in tests the $sniffer service sets its csp | ||
// property after $get has executed. | ||
$parseOptions.csp = $sniffer.csp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still not sure about this though, it seems weird to read this every time $parse is called. If it's the best we can do then that's one thing, but is there not a better solution? |
||
var lexer = new Lexer($parseOptions); | ||
var parser = new Parser(lexer, $filter, $parseOptions); | ||
parsedExpression = parser.parse(exp, false); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, on the other hand.. Maybe something more like
might be cleaner / easier to read, and possibly save a comparison. Although it still technically violates the style guide.
I contradict myself a lot, you'll get used to it ;) I just want to avoid duplicating code, and try to keep it readable and straight forward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that better too, the conditions are basically independent. If I drop the "else" I don't think it violates the style guide, since it references Google's JS style guide, which "follow[s] the C++ formatting rules in spirit", which says "Short conditional statements may be written on one line if this enhances readability." (Yay indirection). And there are several other occurrences of "if (...) return ..." in the Angular source.
Of course the most readable and concise implementation would be to iterate over the array of path components directly, but playing with jsperf showed about a 35% performance hit, which is presumably why it's unrolled into keyN parameters.