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

sanitizeUri function throws an error when ng-href gets an integer #16626

Closed
1 of 3 tasks
szabobgabor opened this issue Jul 12, 2018 · 3 comments
Closed
1 of 3 tasks

sanitizeUri function throws an error when ng-href gets an integer #16626

szabobgabor opened this issue Jul 12, 2018 · 3 comments

Comments

@szabobgabor
Copy link

I'm submitting a ...

  • bug report
  • feature request
  • other

Current behavior:

if i write
<a ng-href="{{ user.id }}">bla</a>
in a template and user.id is an integer
sanitizeUri function (angular.js:19343) throws an error, that uri.trim is not a function (well it is obviously not)

Expected / new behavior:

probably the uri should be casted to string

Minimal reproduction of the problem with instructions:

http://plnkr.co/edit/sd1UHVd8iHF1rPXNL3Z0

AngularJS version: 1.7.2

Browser: [all | Chrome XX | Firefox XX | Edge XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

Anything else:

@petebacondarwin
Copy link
Contributor

Obvious workaround is to call toString() on the value: http://plnkr.co/edit/9qijamnI6UhJK1DP77kU?p=preview

<a ng-href="{{ user.id.toString() }}">bla</a>

@szabobgabor
Copy link
Author

that's true, but not "sexy", and usability breaks

a nicer solution would be to

replace this
var normalizedVal = urlResolve(uri && uri.trim()).href;

into this
var normalizedVal = urlResolve(uri && uri.toString().trim()).href;

@petebacondarwin
Copy link
Contributor

@szabobgabor - yes I agree. This is in fact a regression from 1.6.10 so we do need to fix it.

Narretz added a commit that referenced this issue Aug 20, 2018
Interpolated content in ngHref must be stringified before being passed to $$sanitizeUri by $sce. Before 1.7.x, the sanitization had happened on the already interpolated value inside $compile.

Closes #16652
Fixes #16626
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

3 participants