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): allow for new lines in expr when promise unwrapping is on #4718
Closed
Closed
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -138,7 +138,7 @@ describe('parser', function() { | |
}); | ||
|
||
it('should tokenize function invocation', function() { | ||
var tokens = lex("a()") | ||
var tokens = lex("a()"); | ||
expect(map(tokens, function(t) { return t.text;})).toEqual(['a', '(', ')']); | ||
}); | ||
|
||
|
@@ -199,16 +199,20 @@ describe('parser', function() { | |
}])); | ||
|
||
|
||
forEach([true, false], function(cspEnabled) { | ||
forEach([[true, true],[!0, !1],[!1, !0],[false, false]], function(options /* [csp, unwrapPromises] */) { | ||
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. this is super hard to read. using two nested forEach loops would make the code much more readable. 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 went for the nested forEach approach at first, but I reverted to this because the nested approach would create a huge unnecessary diff (cz of the added indentation) that I wanted to avoid. Didn't want to be blamed for all of the tests, too late now :p |
||
var cspEnabled = options[0], unwrapPromisesEnabled = options[1]; | ||
|
||
describe('csp ' + cspEnabled, function() { | ||
describe('csp ' + cspEnabled + ", unwrapPromises " + unwrapPromisesEnabled, function() { | ||
|
||
beforeEach(module(function ($parseProvider) { | ||
$parseProvider.unwrapPromises(unwrapPromisesEnabled); | ||
})); | ||
|
||
beforeEach(inject(function ($rootScope, $sniffer) { | ||
scope = $rootScope; | ||
$sniffer.csp = cspEnabled; | ||
})); | ||
|
||
|
||
it('should parse expressions', function() { | ||
expect(scope.$eval("-1")).toEqual(-1); | ||
expect(scope.$eval("1 + 2.5")).toEqual(3.5); | ||
|
@@ -590,6 +594,12 @@ describe('parser', function() { | |
expect(scope.$eval('bool.toString()')).toBe('false'); | ||
}); | ||
|
||
it('should evaluate expressions with line terminators', function() { | ||
scope.a = "a"; | ||
scope.b = {c: "bc"}; | ||
expect(scope.$eval('a + \n b.c + \r "\td" + \t \r\n\r "\r\n\n"')).toEqual("abc\td\r\n\n"); | ||
}); | ||
|
||
describe('sandboxing', function() { | ||
describe('Function constructor', function() { | ||
it('should NOT allow access to Function constructor in getter', function() { | ||
|
@@ -768,7 +778,7 @@ describe('parser', function() { | |
// User defined value assigned to constructor. | ||
scope.foo.constructor = function constructor() { | ||
return "custom constructor"; | ||
} | ||
}; | ||
// Dot operator should still block it. | ||
expect(function() { | ||
scope.$eval('foo.constructor()', scope) | ||
|
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.
it should be sufficient to do just:
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.
hm, this isn't 100% equivalent
So the
$1 way
will remove any\n
and\r
from the expression that will be outputted for the warning (hence avoiding the initial error)Is that okay? it's not that important of a bug imo and can be ignored.