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

ngSanitize linky filter throws error if text is truthy but not a string #13547

Closed
CloudNiner opened this issue Dec 15, 2015 · 0 comments
Closed

Comments

@CloudNiner
Copy link

http://jsfiddle.net/an710xcL/16/

Stacktrace thrown in that fiddle:

TypeError: l.match is not a function
    at https://code.angularjs.org/1.4.8/angular-sanitize.min.js:15:169
    at fn (eval at <anonymous> (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js:13365:15), <anonymous>:4:159)
    at regularInterceptedExpression (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js:14446:55)
    at Object.expressionInputWatch [as get] (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js:14347:26)
    at Scope.$digest (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js:15888:40)
    at Scope.$apply (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js:16160:24)
    at bootstrapApply (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js:1679:15)
    at Object.invoke (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js:4523:17)
    at doBootstrap (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js:1677:14)
    at bootstrap (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js:1697:12)

If looping an array or dictionary and linkying each value, it would be nice if mixed types didn't fail.

A simple workaround for now is to cast before passing to linky, e.g:

var text = 42;
$filter('linky')(''+text);
gkalpak added a commit to gkalpak/angular.js that referenced this issue Dec 15, 2015
@gkalpak gkalpak added this to the 1.5.x - migration-facilitation milestone Dec 15, 2015
@gkalpak gkalpak modified the milestones: Backlog, 1.5.x - migration-facilitation Dec 15, 2015
gkalpak added a commit to gkalpak/angular.js that referenced this issue Jan 6, 2016
BREAKING CHANGE:

Before this change, the filter assumed that the input (if not falsy) was of type 'string' and that
certain methods (such as `.match()`) would be available on it. This would most likely result in an
not-very-useful error being thrown (trying to call a method that does not exist) or in unexpected
behavior (if the input happened to have the assumed methods).

After this change, a proper (informative) error will be thrown. If you want to pass non-string
values through `linky`, you need to explicitly convert them to strings first.

Closes angular#13547
gkalpak added a commit to gkalpak/angular.js that referenced this issue Jan 6, 2016
BREAKING CHANGE:

Before this change, the filter assumed that the input (if not falsy) was of type 'string' and that
certain methods (such as `.match()`) would be available on it. This would most likely result in an
not-very-useful error being thrown (trying to call a method that does not exist) or in unexpected
behavior (if the input happened to have the assumed methods).

After this change, a proper (informative) error will be thrown. If you want to pass non-string
values through `linky`, you need to explicitly convert them to strings first.

Closes angular#13547
gkalpak added a commit to gkalpak/angular.js that referenced this issue Jan 7, 2016
BREAKING CHANGE:

Before this change, the filter assumed that the input (if not undefined/null) was of type 'string'
and that certain methods (such as `.match()`) would be available on it. Passing a non-string value
would most likely result in a not-very-useful error being thrown (trying to call a method that does
not exist) or in unexpected behavior (if the input happened to have the assumed methods).

After this change, a proper (informative) error will be thrown. If you want to pass non-string
values through `linky`, you need to explicitly convert them to strings first.
Since input values could be initialized asynchronously, `undefined` or `null` will still be
returned unchanged (without throwing an error).

Closes angular#13547
gkalpak added a commit to gkalpak/angular.js that referenced this issue Jan 8, 2016
BREAKING CHANGE:

Before this change, the filter assumed that the input (if not undefined/null) was of type 'string'
and that certain methods (such as `.match()`) would be available on it. Passing a non-string value
would most likely result in a not-very-useful error being thrown (trying to call a method that does
not exist) or in unexpected behavior (if the input happened to have the assumed methods).

After this change, a proper (informative) error will be thrown. If you want to pass non-string
values through `linky`, you need to explicitly convert them to strings first.
Since input values could be initialized asynchronously, `undefined` or `null` will still be
returned unchanged (without throwing an error).

Closes angular#13547
@gkalpak gkalpak closed this as completed in 98c2db7 Jan 8, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants