@@ -63,52 +63,31 @@ Task<VerifyResult> VerifyXml(XContainer? target)
6363 }
6464
6565 var serialization = settings . serialization ;
66- var nodes = target
66+ var elements = target
6767 . Descendants ( )
6868 . ToList ( ) ;
69- foreach ( var node in nodes )
69+ foreach ( var element in elements )
7070 {
71- if ( serialization . TryGetScrubOrIgnoreByName ( node . Name . LocalName , out var scrubOrIgnore ) )
71+ if ( serialization . TryGetScrubOrIgnoreByName ( element . Name . LocalName , out var scrubOrIgnore ) )
7272 {
7373 if ( scrubOrIgnore == ScrubOrIgnore . Ignore )
7474 {
75- node . Remove ( ) ;
75+ element . Remove ( ) ;
7676 }
7777 else
7878 {
79- node . Value = "Scrubbed" ;
79+ element . Value = "Scrubbed" ;
8080 }
8181
8282 continue ;
8383 }
8484
85- foreach ( var attribute in node
86- . Attributes ( )
87- . ToList ( ) )
88- {
89- if ( serialization . TryGetScrubOrIgnoreByName ( attribute . Name . LocalName , out scrubOrIgnore ) )
90- {
91- if ( scrubOrIgnore == ScrubOrIgnore . Ignore )
92- {
93- attribute . Remove ( ) ;
94- }
95- else
96- {
97- attribute . Value = "Scrubbed" ;
98- }
99-
100- continue ;
101- }
102-
103- attribute . Value = ConvertValue ( serialization , attribute . Value ) ;
104- }
105-
106- if ( node . IsEmpty || node . HasElements )
107- {
108- continue ;
109- }
85+ ScrubAttributes ( element , serialization ) ;
86+ }
11087
111- node . Value = ConvertValue ( serialization , node . Value ) ;
88+ foreach ( var node in target . DescendantNodes ( ) )
89+ {
90+ Debug . WriteLine ( node ) ;
11291 }
11392
11493 return VerifyString ( target . ToString ( ) , "xml" ) ;
@@ -124,4 +103,36 @@ string ConvertValue(SerializationSettings serialization, string value)
124103
125104 return ApplyScrubbers . ApplyForPropertyValue ( span , settings , counter ) . ToString ( ) ;
126105 }
106+
107+ void ScrubAttributes ( XElement node , SerializationSettings serialization )
108+ {
109+ foreach ( var attribute in node
110+ . Attributes ( )
111+ . ToList ( ) )
112+ {
113+ if ( serialization . TryGetScrubOrIgnoreByName ( attribute . Name . LocalName , out var scrubOrIgnore ) )
114+ {
115+ if ( scrubOrIgnore == ScrubOrIgnore . Ignore )
116+ {
117+ attribute . Remove ( ) ;
118+ }
119+ else
120+ {
121+ attribute . Value = "Scrubbed" ;
122+ }
123+
124+ continue ;
125+ }
126+
127+ var span = attribute . Value . AsSpan ( ) ;
128+ if ( serialization . TryConvertString ( counter , span , out var result ) )
129+ {
130+ attribute . Value = result ;
131+ }
132+ else
133+ {
134+ attribute . Value = ApplyScrubbers . ApplyForPropertyValue ( span , settings , counter ) . ToString ( ) ;
135+ }
136+ }
137+ }
127138}
0 commit comments