* @ngdoc method * @name $sceDelegate#getTrusted * * @description * Takes the result of a ng.$sceDelegate#trustAs `$sceDelegate.trustAs` call and * returns the originally supplied value if the queried context
(type, maybeTrusted)
| 18142 | * `$sceDelegate.trustAs`} if valid in this context. Otherwise, throws an exception. |
| 18143 | */ |
| 18144 | function getTrusted(type, maybeTrusted) { |
| 18145 | if (maybeTrusted === null || isUndefined(maybeTrusted) || maybeTrusted === '') { |
| 18146 | return maybeTrusted; |
| 18147 | } |
| 18148 | var constructor = (byType.hasOwnProperty(type) ? byType[type] : null); |
| 18149 | if (constructor && maybeTrusted instanceof constructor) { |
| 18150 | return maybeTrusted.$$unwrapTrustedValue(); |
| 18151 | } |
| 18152 | // If we get here, then we may only take one of two actions. |
| 18153 | // 1. sanitize the value for the requested type, or |
| 18154 | // 2. throw an exception. |
| 18155 | if (type === SCE_CONTEXTS.RESOURCE_URL) { |
| 18156 | if (isResourceUrlAllowedByPolicy(maybeTrusted)) { |
| 18157 | return maybeTrusted; |
| 18158 | } else { |
| 18159 | throw $sceMinErr('insecurl', |
| 18160 | 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: {0}', |
| 18161 | maybeTrusted.toString()); |
| 18162 | } |
| 18163 | } else if (type === SCE_CONTEXTS.HTML) { |
| 18164 | return htmlSanitizer(maybeTrusted); |
| 18165 | } |
| 18166 | throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.'); |
| 18167 | } |
| 18168 | |
| 18169 | return { |
| 18170 | trustAs: trustAs, |
no test coverage detected