* @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)
| 17669 | * `$sceDelegate.trustAs`} if valid in this context. Otherwise, throws an exception. |
| 17670 | */ |
| 17671 | function getTrusted(type, maybeTrusted) { |
| 17672 | if (maybeTrusted === null || isUndefined(maybeTrusted) || maybeTrusted === '') { |
| 17673 | return maybeTrusted; |
| 17674 | } |
| 17675 | var constructor = (byType.hasOwnProperty(type) ? byType[type] : null); |
| 17676 | if (constructor && maybeTrusted instanceof constructor) { |
| 17677 | return maybeTrusted.$$unwrapTrustedValue(); |
| 17678 | } |
| 17679 | // If we get here, then we may only take one of two actions. |
| 17680 | // 1. sanitize the value for the requested type, or |
| 17681 | // 2. throw an exception. |
| 17682 | if (type === SCE_CONTEXTS.RESOURCE_URL) { |
| 17683 | if (isResourceUrlAllowedByPolicy(maybeTrusted)) { |
| 17684 | return maybeTrusted; |
| 17685 | } else { |
| 17686 | throw $sceMinErr('insecurl', |
| 17687 | 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: {0}', |
| 17688 | maybeTrusted.toString()); |
| 17689 | } |
| 17690 | } else if (type === SCE_CONTEXTS.HTML) { |
| 17691 | return htmlSanitizer(maybeTrusted); |
| 17692 | } |
| 17693 | throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.'); |
| 17694 | } |
| 17695 | |
| 17696 | return { trustAs: trustAs, |
| 17697 | getTrusted: getTrusted, |
no test coverage detected