@@ -41,7 +41,7 @@ import {
4141 simpleCompare ,
4242 trim ,
4343} from "../../shared/utils.ts" ;
44- import { SCE_CONTEXTS } from "../../services/sce/sce.ts" ;
44+ import { SCE_CONTEXTS , type SceContext } from "../../services/sce/sce.ts" ;
4545import { PREFIX_REGEXP } from "../../shared/constants.ts" ;
4646import {
4747 createEventDirective ,
@@ -344,7 +344,7 @@ export interface TextInterpolateLinkState {
344344export interface AttrInterpolateLinkState {
345345 _name : string ;
346346 _value : string ;
347- _trustedContext ?: string ;
347+ _trustedContext ?: SceContext ;
348348 _allOrNothing : boolean ;
349349 _interpolateFn ?: InterpolationFunction ;
350350}
@@ -910,7 +910,14 @@ export class CompileProvider {
910910 /**
911911 * The security context of DOM Properties.
912912 */
913- const PROP_CONTEXTS = nullObject ( ) as Record < string , string > ;
913+ const PROP_CONTEXTS = nullObject ( ) as Record < string , SceContext > ;
914+
915+ const LEGACY_SCE_CONTEXTS : Record < string , SceContext > = {
916+ html : SCE_CONTEXTS . _HTML ,
917+ mediaUrl : SCE_CONTEXTS . _MEDIA_URL ,
918+ resourceUrl : SCE_CONTEXTS . _RESOURCE_URL ,
919+ url : SCE_CONTEXTS . _URL ,
920+ } ;
914921
915922 /**
916923 * Defines the security context for DOM properties bound by ng-prop-*.
@@ -925,20 +932,22 @@ export class CompileProvider {
925932 propertyName : string ,
926933 ctx : string ,
927934 ) {
935+ const normalizedCtx = LEGACY_SCE_CONTEXTS [ ctx ] || ctx ;
936+
928937 const key = `${ elementName . toLowerCase ( ) } |${ propertyName . toLowerCase ( ) } ` ;
929938
930- if ( key in PROP_CONTEXTS && PROP_CONTEXTS [ key ] !== ctx ) {
939+ if ( key in PROP_CONTEXTS && PROP_CONTEXTS [ key ] !== normalizedCtx ) {
931940 throw $compileMinErr (
932941 "ctxoverride" ,
933942 "Property context '{0}.{1}' already set to '{2}', cannot override to '{3}'." ,
934943 elementName ,
935944 propertyName ,
936945 PROP_CONTEXTS [ key ] ,
937- ctx ,
946+ normalizedCtx ,
938947 ) ;
939948 }
940949
941- PROP_CONTEXTS [ key ] = ctx ;
950+ PROP_CONTEXTS [ key ] = normalizedCtx as SceContext ;
942951
943952 return this ;
944953 } ;
@@ -953,18 +962,18 @@ export class CompileProvider {
953962 */
954963 ( function registerNativePropertyContexts ( ) {
955964 /** Registers the same security context for a list of `element|property` keys. */
956- function registerContext ( ctx : string , items : string [ ] ) {
965+ function registerContext ( ctx : SceContext , items : string [ ] ) {
957966 items . forEach ( ( v ) => {
958967 PROP_CONTEXTS [ v . toLowerCase ( ) ] = ctx ;
959968 } ) ;
960969 }
961970
962- registerContext ( SCE_CONTEXTS . HTML , [
971+ registerContext ( SCE_CONTEXTS . _HTML , [
963972 "iframe|srcdoc" ,
964973 "*|innerHTML" ,
965974 "*|outerHTML" ,
966975 ] ) ;
967- registerContext ( SCE_CONTEXTS . URL , [
976+ registerContext ( SCE_CONTEXTS . _URL , [
968977 "area|href" ,
969978 "area|ping" ,
970979 "a|href" ,
@@ -976,7 +985,7 @@ export class CompileProvider {
976985 "ins|cite" ,
977986 "q|cite" ,
978987 ] ) ;
979- registerContext ( SCE_CONTEXTS . MEDIA_URL , [
988+ registerContext ( SCE_CONTEXTS . _MEDIA_URL , [
980989 "audio|src" ,
981990 "img|src" ,
982991 "img|srcset" ,
@@ -986,7 +995,7 @@ export class CompileProvider {
986995 "video|src" ,
987996 "video|poster" ,
988997 ] ) ;
989- registerContext ( SCE_CONTEXTS . RESOURCE_URL , [
998+ registerContext ( SCE_CONTEXTS . _RESOURCE_URL , [
990999 "*|formAction" ,
9911000 "applet|code" ,
9921001 "applet|codebase" ,
@@ -3490,9 +3499,9 @@ export class CompileProvider {
34903499 function getTrustedAttrContext (
34913500 nodeName : string ,
34923501 attrNormalizedName : string ,
3493- ) {
3502+ ) : SceContext | undefined {
34943503 if ( attrNormalizedName === "srcdoc" ) {
3495- return $sce . HTML ;
3504+ return SCE_CONTEXTS . _HTML ;
34963505 }
34973506
34983507 // All nodes with src attributes require a RESOURCE_URL value, except for
@@ -3502,30 +3511,30 @@ export class CompileProvider {
35023511 [ "img" , "video" , "audio" , "source" , "track" ] . indexOf ( nodeName ) ===
35033512 - 1
35043513 ) {
3505- return $sce . RESOURCE_URL ;
3514+ return SCE_CONTEXTS . _RESOURCE_URL ;
35063515 }
35073516
3508- return $sce . MEDIA_URL ;
3517+ return SCE_CONTEXTS . _MEDIA_URL ;
35093518 }
35103519
35113520 if ( attrNormalizedName === "xlinkHref" ) {
35123521 // Some xlink:href are okay, most aren't
35133522 if ( nodeName === "image" ) {
3514- return $sce . MEDIA_URL ;
3523+ return SCE_CONTEXTS . _MEDIA_URL ;
35153524 }
35163525
35173526 if ( nodeName === "a" ) {
3518- return $sce . URL ;
3527+ return SCE_CONTEXTS . _URL ;
35193528 }
35203529
3521- return $sce . RESOURCE_URL ;
3530+ return SCE_CONTEXTS . _RESOURCE_URL ;
35223531 }
35233532
35243533 if (
35253534 nodeName === "image" &&
35263535 ( attrNormalizedName === "href" || attrNormalizedName === "ngHref" )
35273536 ) {
3528- return $sce . MEDIA_URL ;
3537+ return SCE_CONTEXTS . _MEDIA_URL ;
35293538 }
35303539
35313540 if (
@@ -3537,14 +3546,14 @@ export class CompileProvider {
35373546 // links can be stylesheets or imports, which can run script in the current origin
35383547 ( nodeName === "link" && attrNormalizedName === "href" )
35393548 ) {
3540- return $sce . RESOURCE_URL ;
3549+ return SCE_CONTEXTS . _RESOURCE_URL ;
35413550 }
35423551
35433552 if (
35443553 nodeName === "a" &&
35453554 ( attrNormalizedName === "href" || attrNormalizedName === "ngHref" )
35463555 ) {
3547- return $sce . URL ;
3556+ return SCE_CONTEXTS . _URL ;
35483557 }
35493558
35503559 return undefined ;
@@ -3554,7 +3563,7 @@ export class CompileProvider {
35543563 function getTrustedPropContext (
35553564 nodeName : string ,
35563565 propNormalizedName : string ,
3557- ) {
3566+ ) : SceContext | undefined {
35583567 const prop = propNormalizedName . toLowerCase ( ) ;
35593568
35603569 return (
0 commit comments