danday74 danday74 - 1 month ago 4
AngularJS Question

angular trusting a url - to escape or not to escape

this angular filter works great but do i include the line encodeURI or not?
i.e. does angular $sce.trustAsResourceUrl do it for you? the docs are silent.

angular
.module('admin')
.filter('trustUrl', trustUrl);

trustUrl.$inject = ['$sce'];

function trustUrl($sce) {
return function (url) {
url = encodeURI(url); // <<<< NEEDED ?
return $sce.trustAsResourceUrl(url);
};
}

Answer

I think I left it in in the end since it didn't seem to cause any harm

Comments