* @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 is a supertype of the * created type. If this co
(type, maybeTrusted)
| 17228 | * `$sceDelegate.trustAs`} if valid in this context. Otherwise, throws an exception. |
| 17229 | */ |
| 17230 | function getTrusted(type, maybeTrusted) { |
| 17231 | if (maybeTrusted === null || isUndefined(maybeTrusted) || maybeTrusted === '') { |
| 17232 | return maybeTrusted; |
| 17233 | } |
| 17234 | var constructor = (byType.hasOwnProperty(type) ? byType[type] : null); |
| 17235 | if (constructor && maybeTrusted instanceof constructor) { |
| 17236 | return maybeTrusted.$$unwrapTrustedValue(); |
| 17237 | } |
| 17238 | // If we get here, then we may only take one of two actions. |
| 17239 | // 1. sanitize the value for the requested type, or |
| 17240 | // 2. throw an exception. |
| 17241 | if (type === SCE_CONTEXTS.RESOURCE_URL) { |
| 17242 | if (isResourceUrlAllowedByPolicy(maybeTrusted)) { |
| 17243 | return maybeTrusted; |
| 17244 | } else { |
| 17245 | throw $sceMinErr('insecurl', |
| 17246 | 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: {0}', |
| 17247 | maybeTrusted.toString()); |
| 17248 | } |
| 17249 | } else if (type === SCE_CONTEXTS.HTML) { |
| 17250 | return htmlSanitizer(maybeTrusted); |
| 17251 | } |
| 17252 | throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.'); |
| 17253 | } |
| 17254 | |
| 17255 | return { trustAs: trustAs, |
| 17256 | getTrusted: getTrusted, |
no test coverage detected