Description
Regex Template (MATCH_PATTERN_XML_TEMPLATE) used in MaskSensitiveHelper class for replace all ocurrs of element in XML is getting always only one ocurrs when you have a list of elements to replace.
In this sample of xml
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns1:listResponse xmlns:ns1="http://acme.org/"> <return xmlns:ns2="http://acme.org/"> <description>Winter fruit</description> <name>Apple1</name> </return> <return xmlns:ns2="http://acme.org/"> <description>Tropical fruit</description> <name>Pineapple1</name> </return> </ns1:listResponse> </soap:Body> </soap:Envelope>
if you need to replace the content of element <description>, the regex used for
"(<description.*>)(.*?)(</description>)"
will started at '<description>Winter fruit' and end at
'Tropical fruit</description>' , because of this the replaceAll will replace the last occurs in XML.
To fix it we have to change the match pattern xml template.
The correct value for it has to be
private static final String MATCH_PATTERN_XML_TEMPLATE = "(<-ELEMENT_NAME-*.?>)(.*?)(</-ELEMENT_NAME->)";
not
private static final String MATCH_PATTERN_XML_TEMPLATE = "(<-ELEMENT_NAME-.*>)(.*?)(</-ELEMENT_NAME->)";