-
Notifications
You must be signed in to change notification settings - Fork 27.4k
filter Filter will convert null and undefined to strings #11432
Comments
I don't see it, maybe I don't understand the problem. |
This sounds somehow similar to #11312 - different filter but the same root cause. |
Maybe this update plunker will make it a bit clearer I have two values in the array where name is not a string - one is null and one is undefined [{name:null, phone:'The value of name is null'},
{name:undefined, phone:'The value of name is undefined'},
{name:'Mike', phone:'555-4321'},
{name:'Adam', phone:'555-5678'},
{name:'Julie', phone:'555-8765'},
{name:'Juliette', phone:'555-5678'}] If I search this array for names with 'u', you would expect only Julie and Juliette to return. But, also the null and undefined results are returned. The filter filter is treating null and undefined as strings, and then using the converted string value to determine if the array matches the search. If I change the Angular version to 1.3.5, the filter filter works as expected |
And here is the offending line actual = lowercase('' + actual); This line implicitly converts null into "null" and undefined into "undefined" |
Agree that it's very similar to my bug, #11312. Sadly, the broken code isn't shared. :) |
Yeh, this is a valid one. |
I always have a hard time differentiating between bug fixes and breaking changes when it comes to The desired behaviour is:
(Currently, (1) and (3) match if the filter expression is a subtring of Do I miss something ? |
I think it's probably expected behavior that null/undefined filter |
They don't do that today (nor did they do it pre 1.3.6) and I don't think they (both) should. An A |
I think I got confused and probably was conflating explicit null in a filter with the empty string. Yes, I agree that what you say here. |
Included fixes: * Do not convert `null`/`undefined` to strings for substring matching in non-strict comparison mode. Prevents `null`/`undefined` from being matched against e.g. 'u'. * Let `null` (as a top-level filter expression) match "deeply" (as do booleans, numbers and strings). E.g. let `filterFilter(arr, null)` match an item like `{someProp: null}`. Closes angular#11432
Included fixes: * Do not convert `null`/`undefined` to strings for substring matching in non-strict comparison mode. Prevents `null`/`undefined` from being matched against e.g. 'u'. * Let `null` (as a top-level filter expression) match "deeply" (as do booleans, numbers and strings). E.g. let `filterFilter(arr, null)` match an item like `{someProp: null}`. Closes angular#11432
Included fixes: * Do not convert `null`/`undefined` to strings for substring matching in non-strict comparison mode. Prevents `null`/`undefined` from being matched against e.g. 'u'. * Let `null` (as a top-level filter expression) match "deeply" (as do booleans, numbers and strings). E.g. let `filterFilter(arr, null)` match an item like `{someProp: null}`. Closes angular#11432
Included fixes: * Do not convert `null`/`undefined` to strings for substring matching in non-strict comparison mode. Prevents `null`/`undefined` from being matched against e.g. 'u'. * Let `null` (as a top-level filter expression) match "deeply" (as do booleans, numbers and strings). E.g. let `filterFilter(arr, null)` match an item like `{someProp: null}`. Closes angular#11432 Closes angular#11445
filterFilter will convert null and undefined to strings and use that to filter
This makes the default comparator unusable with arrays that have fields with null or undefined values.
This seems to be a regression - it works as expected in <=1.3.5
Here is plnkr
http://plnkr.co/edit/P67JlZv83ea8J5ZFw9Ce?p=preview
The text was updated successfully, but these errors were encountered: