* @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)
| 15159 | * `$sceDelegate.trustAs`} if valid in this context. Otherwise, throws an exception. |
| 15160 | */ |
| 15161 | function getTrusted(type, maybeTrusted) { |
| 15162 | if (maybeTrusted === null || maybeTrusted === undefined || maybeTrusted === '') { |
| 15163 | return maybeTrusted; |
| 15164 | } |
| 15165 | var constructor = (byType.hasOwnProperty(type) ? byType[type] : null); |
| 15166 | if (constructor && maybeTrusted instanceof constructor) { |
| 15167 | return maybeTrusted.$$unwrapTrustedValue(); |
| 15168 | } |
| 15169 | // If we get here, then we may only take one of two actions. |
| 15170 | // 1. sanitize the value for the requested type, or |
| 15171 | // 2. throw an exception. |
| 15172 | if (type === SCE_CONTEXTS.RESOURCE_URL) { |
| 15173 | if (isResourceUrlAllowedByPolicy(maybeTrusted)) { |
| 15174 | return maybeTrusted; |
| 15175 | } else { |
| 15176 | throw $sceMinErr('insecurl', |
| 15177 | 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: {0}', |
| 15178 | maybeTrusted.toString()); |
| 15179 | } |
| 15180 | } else if (type === SCE_CONTEXTS.HTML) { |
| 15181 | return htmlSanitizer(maybeTrusted); |
| 15182 | } |
| 15183 | throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.'); |
| 15184 | } |
| 15185 | |
| 15186 | return { trustAs: trustAs, |
| 15187 | getTrusted: getTrusted, |
no test coverage detected