-
Notifications
You must be signed in to change notification settings - Fork 27.3k
fix($parse): treat falsy values as defined in assignment expressions #14994
Conversation
e3b5ab8
to
45674dc
Compare
@@ -1274,6 +1274,10 @@ ASTCompiler.prototype = { | |||
return '!(' + expression + ')'; | |||
}, | |||
|
|||
null: function(expression) { |
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.
Please rename to isNull
Looks like variations of the same issue are present at with the expressions It would be best to fix the three cases in one go. |
@lgalfaso I have a problem with the unit test.
I get this error 'Expected function to throw an exception' I have no idea why toThrow() doesn't detect that TypeError was thrown from parse function ? |
There are at least 2 parts: The There might be discrepancies on how this is handled in different browsers. |
45674dc
to
d44c539
Compare
@lgalfaso
I get TypeError: Cannot create property 'b' on number '0' Case 2:
I get TypeError: Cannot create property 'b' on number '0' Case 3:
This shouldn't throw any error because assigning 'a' with another value. Is that what you mean ? |
For some reasons that are not important, the following 3 expressions follow 3 slightly different code paths foo.bar = 1;
foo.bar.baz = 1;
foo.bar['baz'] = 1; In this case we want to fix the three of them as they all have the same issue. This is, the following cases should behave in the same way $parse('foo.bar = 1')({foo: 0});
$parse('foo.bar.baz = 1')({foo: {bar: 0}});
$parse('foo.bar["baz"] = 1')({foo: {bar: 0}}); |
d44c539
to
677dd3d
Compare
After I handled these two cases
Some old cases failed
and
So these Cases are against the the change to handle
so what is your suggestion ? |
@@ -3900,6 +3900,34 @@ describe('parser', function() { | |||
expect(isFunction(s.toString)).toBe(true); | |||
expect(l.toString).toBe(1); | |||
})); | |||
|
|||
it('should assign a property to locals properties with null or undefined value', inject(function($parse) { |
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.
The description is misleading. There is no locals object in the test. Use scope instead.
The tests you mentioned were affected by the bug you fixed. You could change the initial values to something that can be assigned to, e.g.: // Before:
{foo: {constructor: ''}}
{foo: {constructor: {prototype: ''}}}
// After:
{foo: {constructor: {}}}
{foo: {constructor: {prototype: {}}}} |
677dd3d
to
38038e9
Compare
@gkalpak
I get this error. but when i use
I get I have no Idea why the test didn't detect the thrown exception, but when i used Does angular handle these exception in a different way ? or I am missing something. |
7060488
to
bf9cbef
Compare
@m-amr, I see you pushed another commit. Were you able to solve the issue you had or should I take a look? |
@gkalpak, No I still have the same problem, Could you please check it. |
bf9cbef
to
2493520
Compare
2493520
to
4a2c3f2
Compare
bab639c
to
21e225a
Compare
21e225a
to
d6beae8
Compare
d6beae8
to
0cb3cb2
Compare
0cb3cb2
to
36ddd18
Compare
36ddd18
to
497281e
Compare
497281e
to
4102e33
Compare
@gkalpak |
4102e33
to
14eaaf2
Compare
14eaaf2
to
afc91f4
Compare
afc91f4
to
2e78764
Compare
function tryParseAndIgnoreException(expression) { | ||
try { | ||
$parse(expression)(scope); | ||
} catch (error) {/** ignore exception*/} |
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.
Nit: Use /* ... */
(and consistent whitespace).
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.
Done.
LGTM |
2e78764
to
859ab01
Compare
859ab01
to
d3cffcf
Compare
LGTM |
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
bug, solving Issue #14990
Closes #14990