@@ -1071,6 +1071,37 @@ public void TestScriptObjectAccessor()
10711071 Assert . False ( accessor . HasMember ( context , new SourceSpan ( ) , obj , nameof ( MyStaticObject . StaticPropertyA ) ) ) ;
10721072 Assert . False ( accessor . HasMember ( context , new SourceSpan ( ) , obj , nameof ( MyStaticObject . StaticPropertyB ) ) ) ;
10731073 }
1074+
1075+ // Test Reset clears cached typed accessors that captured the previous MemberFilter
1076+ {
1077+ var context = new TemplateContext
1078+ {
1079+ EnableRelaxedMemberAccess = false ,
1080+ MemberFilter = _ => true
1081+ } ;
1082+ var obj = new MyObject { PropertyA = "allowed" , PropertyB = "blocked" } ;
1083+ var template = Template . Parse ( "{{ model.property_b }}" ) ;
1084+ var accessor = context . GetMemberAccessor ( obj ) ;
1085+ var globals = new ScriptObject ( ) ;
1086+ globals [ "model" ] = obj ;
1087+ context . PushGlobal ( globals ) ;
1088+
1089+ Assert . True ( accessor . HasMember ( context , new SourceSpan ( ) , obj , "property_b" ) ) ;
1090+ Assert . AreEqual ( "blocked" , template . Render ( context ) ) ;
1091+
1092+ context . Reset ( ) ;
1093+ context . MemberFilter = member => member . Name == nameof ( MyObject . PropertyA ) ;
1094+
1095+ accessor = context . GetMemberAccessor ( obj ) ;
1096+ Assert . False ( accessor . HasMember ( context , new SourceSpan ( ) , obj , "property_b" ) ) ;
1097+
1098+ globals = new ScriptObject ( ) ;
1099+ globals [ "model" ] = obj ;
1100+ context . PushGlobal ( globals ) ;
1101+
1102+ var exception = Assert . Throws < ScriptRuntimeException > ( ( ) => template . Render ( context ) ) ;
1103+ StringAssert . Contains ( "Cannot get member" , exception ! . Message ) ;
1104+ }
10741105 }
10751106
10761107 [ Test ]
0 commit comments