MCPcopy Create free account
hub / github.com/angular-ui/ui-grid / getTrusted

Function getTrusted

lib/test/angular/1.6.7/angular.js:19426–19455  ·  view source on GitHub ↗

* @ngdoc method * @name $sceDelegate#getTrusted * * @description * Takes any input, and either returns a value that's safe to use in the specified context, or * throws an exception. * * In practice, there are several cases. When given a string, this function runs c

(type, maybeTrusted)

Source from the content-addressed store, hash-verified

19424 * exception if this is impossible.
19425 */
19426 function getTrusted(type, maybeTrusted) {
19427 if (maybeTrusted === null || isUndefined(maybeTrusted) || maybeTrusted === '') {
19428 return maybeTrusted;
19429 }
19430 var constructor = (byType.hasOwnProperty(type) ? byType[type] : null);
19431 // If maybeTrusted is a trusted class instance or subclass instance, then unwrap and return
19432 // as-is.
19433 if (constructor && maybeTrusted instanceof constructor) {
19434 return maybeTrusted.$$unwrapTrustedValue();
19435 }
19436 // Otherwise, if we get here, then we may either make it safe, or throw an exception. This
19437 // depends on the context: some are sanitizatible (HTML), some use whitelists (RESOURCE_URL),
19438 // some are impossible to do (JS). This step isn't implemented for CSS and URL, as AngularJS
19439 // has no corresponding sinks.
19440 if (type === SCE_CONTEXTS.RESOURCE_URL) {
19441 // RESOURCE_URL uses a whitelist.
19442 if (isResourceUrlAllowedByPolicy(maybeTrusted)) {
19443 return maybeTrusted;
19444 } else {
19445 throw $sceMinErr('insecurl',
19446 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: {0}',
19447 maybeTrusted.toString());
19448 }
19449 } else if (type === SCE_CONTEXTS.HTML) {
19450 // htmlSanitizer throws its own error when no sanitizer is available.
19451 return htmlSanitizer(maybeTrusted);
19452 }
19453 // Default error when the $sce service has no way to make the input safe.
19454 throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.');
19455 }
19456
19457 return { trustAs: trustAs,
19458 getTrusted: getTrusted,

Callers 1

$SceProviderFunction · 0.70

Calls 3

isUndefinedFunction · 0.70
htmlSanitizerFunction · 0.70

Tested by

no test coverage detected