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

Wrong cast to boolean #4277

Closed
zakjan opened this issue Oct 4, 2013 · 7 comments
Closed

Wrong cast to boolean #4277

zakjan opened this issue Oct 4, 2013 · 7 comments
Assignees
Milestone

Comments

@zakjan
Copy link

zakjan commented Oct 4, 2013

toBoolean(window) === false

because of that toBoolean(value) function checks value.length property, which means for window the count of (i)frames - usually 0.

@petebacondarwin
Copy link
Member

@zakjan - Can you give the context where this is causing problems?

@zakjan
Copy link
Author

zakjan commented Oct 8, 2013

I found this when used ng-show="someVar", and in my case someVar can be a window object. So it is a very edge case.

Quick solution was to double-not (!!) someVar.

@leostera
Copy link
Contributor

leostera commented Oct 8, 2013

Should this be defaulted?

On Tue, Oct 8, 2013 at 7:56 AM, Jan Žák notifications@github.com wrote:

I found this when used ng-show="someVar", and in my case someVar can be a
window object. So it is a very edge case.

Quick solution was to double-not (!!) someVar.


Reply to this email directly or view it on GitHubhttps://github.com//issues/4277#issuecomment-25880454
.

@petebacondarwin
Copy link
Member

Hmm, well ng-show="[]" also hides the element, even though in the console

if([]) { console.log('true'); }
> "true"

@leostera
Copy link
Contributor

leostera commented Oct 8, 2013

This is where we are looking at:

function toBoolean(value) {

It explicitly handles the "[]" case.

On Tue, Oct 8, 2013 at 9:52 AM, Pete Bacon Darwin
notifications@github.comwrote:

Hmm, well ng-show="[]" also hides the element, even though in the console

if([]) { console.log('true'); }> "true"


Reply to this email directly or view it on GitHubhttps://github.com//issues/4277#issuecomment-25886662
.

@zakjan
Copy link
Author

zakjan commented Oct 8, 2013

So maybe the fix could be to separate array length check just for arrays:

if (isArray(value)) {
  value = value.length !== 0;
} else if ...

@capaj
Copy link

capaj commented Dec 15, 2013

There is also another issue with functions: #5414

lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Dec 30, 2013
Make ngShow and ngHide follow javascript `truthy`/`falsy` logic and
not the custom toBoolean logic

Fixes angular#5414 angular#4277
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Dec 30, 2013
Make ngShow and ngHide follow javascript `truthy`/`falsy` logic and
not the custom toBoolean logic

Fixes angular#5414 angular#4277

BREAKING CHANGE: The expressions

* `<div ng-hide="[]">X</div>`
* `<div ng-hide="'f'">X</div>`
* `<div ng-hide="'[]'">X</div>`

used to be evaluated to `false` and the elements were hidden.

The same effect is present for `ng-show` and the elements are now visible
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Dec 30, 2013
Make ngShow and ngHide follow javascript `truthy`/`falsy` logic and
not the custom toBoolean logic

Fixes angular#5414 angular#4277

BREAKING CHANGE: The expressions

* `<div ng-hide="[]">X</div>`
* `<div ng-hide="'f'">X</div>`
* `<div ng-hide="'[]'">X</div>`

used to be evaluated to `false` and the elements were hidden.

The same effect is present for `ng-show` and the elements are now visible

If you were previously doing `ng-show="exp"` where
  `$scope.exp = 'no' // (or 'n' or 'f')`, then instead write
  `ng-show="exp && exp !== 'no'` (or 'n' or 'f').
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Feb 5, 2014
Make ngShow and ngHide follow javascript `truthy`/`falsy` logic and
not the custom toBoolean logic

Fixes angular#5414 angular#4277 angular#3969

BREAKING CHANGE: The expressions

* `<div ng-hide="[]">X</div>`
* `<div ng-hide="'f'">X</div>`
* `<div ng-hide="'[]'">X</div>`

used to be evaluated to `false` and the elements were hidden.

The same effect is present for `ng-show` and the elements are now
  visible; and with `ng-if` and the elements are now removed

If you were previously doing `ng-show="exp"` where
  `$scope.exp = 'no' // (or 'n' or 'f')`, then instead write
  `ng-show="exp && exp !== 'no'` (or 'n' or 'f').
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Feb 5, 2014
Make ngIf, ngShow and ngHide follow javascript `truthy`/`falsy`
logic and not the custom toBoolean logic

Fixes angular#5414 angular#4277 angular#3969

BREAKING CHANGE: The expressions

* `<div ng-hide="[]">X</div>`
* `<div ng-hide="'f'">X</div>`
* `<div ng-hide="'[]'">X</div>`

used to be evaluated to `false` and the elements were hidden.

The same effect is present for `ng-show` and the elements are now
  visible; and with `ng-if` and the elements are now removed

If you were previously doing `ng-show="exp"` where
  `$scope.exp = 'no' // (or 'n' or 'f')`, then instead write
  `ng-show="exp && exp !== 'no'` (or 'n' or 'f').
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Jun 5, 2014
Make ngIf, ngShow and ngHide follow javascript `truthy`/`falsy`
logic and not the custom toBoolean logic

Fixes angular#5414 angular#4277 angular#3969

BREAKING CHANGE: The expressions

* `<div ng-hide="[]">X</div>`
* `<div ng-hide="'f'">X</div>`
* `<div ng-hide="'[]'">X</div>`

used to be evaluated to `false` and the elements were hidden.

The same effect is present for `ng-show` and the elements are now
  visible; and with `ng-if` and the elements are now removed

If you were previously doing `ng-show="exp"` where
  `$scope.exp = 'no' // (or 'n' or 'f')`, then instead write
  `ng-show="exp && exp !== 'no'` (or 'n' or 'f').
@IgorMinar IgorMinar modified the milestones: 1.3.0-beta.14, Backlog Jun 22, 2014
mgol added a commit to mgol/angular.js that referenced this issue Jun 23, 2014
So far Angular have used the toBoolean function to decide if the parsed value
is truthy. The function made more values falsy than regular JavaScript would,
e.g. strings 'f' and 'no' were both treated as falsy. This creates suble bugs
when backend sends a non-empty string with one of these values and something
suddenly hides in the application

BREAKING CHANGE: values 'f', '0', 'false', 'no', 'n', '[]' are no longer
treated as falsy; only JavaScript falsy values are treated as falsy by the
expression parser; there are six of them: false, null, undefined, NaN, o and "".

Fixes angular#3969
Fixes angular#4277
mgol added a commit to mgol/angular.js that referenced this issue Jun 23, 2014
So far Angular have used the toBoolean function to decide if the parsed value
is truthy. The function made more values falsy than regular JavaScript would,
e.g. strings 'f' and 'no' were both treated as falsy. This creates suble bugs
when backend sends a non-empty string with one of these values and something
suddenly hides in the application

BREAKING CHANGE: values 'f', '0', 'false', 'no', 'n', '[]' are no longer
treated as falsy. Only JavaScript falsy values are now treated as falsy by the
expression parser; there are six of them: false, null, undefined, NaN, o and "".

Fixes angular#3969
Fixes angular#4277
mgol added a commit to mgol/angular.js that referenced this issue Jun 23, 2014
So far Angular have used the toBoolean function to decide if the parsed value
is truthy. The function made more values falsy than regular JavaScript would,
e.g. strings 'f' and 'no' were both treated as falsy. This creates suble bugs
when backend sends a non-empty string with one of these values and something
suddenly hides in the application

BREAKING CHANGE: values 'f', '0', 'false', 'no', 'n', '[]' are no longer
treated as falsy. Only JavaScript falsy values are now treated as falsy by the
expression parser; there are six of them: false, null, undefined, NaN, o and "".

Fixes angular#3969
Fixes angular#4277
mgol added a commit to mgol/angular.js that referenced this issue Jun 23, 2014
So far Angular have used the toBoolean function to decide if the parsed value
is truthy. The function made more values falsy than regular JavaScript would,
e.g. strings 'f' and 'no' were both treated as falsy. This creates suble bugs
when backend sends a non-empty string with one of these values and something
suddenly hides in the application

BREAKING CHANGE: values 'f', '0', 'false', 'no', 'n', '[]' are no longer
treated as falsy. Only JavaScript falsy values are now treated as falsy by the
expression parser; there are six of them: false, null, undefined, NaN, 0 and "".

Fixes angular#3969
Fixes angular#4277
mgol added a commit to mgol/angular.js that referenced this issue Jun 24, 2014
So far Angular have used the toBoolean function to decide if the parsed value
is truthy. The function made more values falsy than regular JavaScript would,
e.g. strings 'f' and 'no' were both treated as falsy. This creates suble bugs
when backend sends a non-empty string with one of these values and something
suddenly hides in the application

Thanks to lgalfaso for test ideas.

BREAKING CHANGE: values 'f', '0', 'false', 'no', 'n', '[]' are no longer
treated as falsy. Only JavaScript falsy values are now treated as falsy by the
expression parser; there are six of them: false, null, undefined, NaN, 0 and "".

Fixes angular#3969
Fixes angular#4277
mgol added a commit to mgol/angular.js that referenced this issue Jun 24, 2014
So far Angular have used the toBoolean function to decide if the parsed value
is truthy. The function made more values falsy than regular JavaScript would,
e.g. strings 'f' and 'no' were both treated as falsy. This creates suble bugs
when backend sends a non-empty string with one of these values and something
suddenly hides in the application

Thanks to lgalfaso for test ideas.

BREAKING CHANGE: values 'f', '0', 'false', 'no', 'n', '[]' are no longer
treated as falsy. Only JavaScript falsy values are now treated as falsy by the
expression parser; there are six of them: false, null, undefined, NaN, 0 and "".

Fixes angular#3969
Fixes angular#4277
mgol added a commit to mgol/angular.js that referenced this issue Jun 25, 2014
So far Angular have used the toBoolean function to decide if the parsed value
is truthy. The function made more values falsy than regular JavaScript would,
e.g. strings 'f' and 'no' were both treated as falsy. This creates suble bugs
when backend sends a non-empty string with one of these values and something
suddenly hides in the application

Thanks to lgalfaso for test ideas.

BREAKING CHANGE: values 'f', '0', 'false', 'no', 'n', '[]' are no longer
treated as falsy. Only JavaScript falsy values are now treated as falsy by the
expression parser; there are six of them: false, null, undefined, NaN, 0 and "".

Fixes angular#3969
Fixes angular#4277
@mgol mgol closed this as completed in bdfc9c0 Jun 26, 2014
ckknight pushed a commit to ckknight/angular.js that referenced this issue Jul 16, 2014
So far Angular have used the toBoolean function to decide if the parsed value
is truthy. The function made more values falsy than regular JavaScript would,
e.g. strings 'f' and 'no' were both treated as falsy. This creates suble bugs
when backend sends a non-empty string with one of these values and something
suddenly hides in the application

Thanks to lgalfaso for test ideas.

BREAKING CHANGE: values 'f', '0', 'false', 'no', 'n', '[]' are no longer
treated as falsy. Only JavaScript falsy values are now treated as falsy by the
expression parser; there are six of them: false, null, undefined, NaN, 0 and "".

Closes angular#3969
Closes angular#4277
Closes angular#7960
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.