Skip to content

Commit

Permalink
ZCS-16214
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishkataria86 authored Nov 26, 2024
1 parent 79725a4 commit 3c29524
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/main/java/org/owasp/validator/html/scan/AntiSamyDOMScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,26 @@ public AntiSamyDOMScanner() throws PolicyException {
// Method to decode the Unicode escape sequences
private String decodeUnicodeEscapes(String input) {
try {
StringBuffer decodedString = new StringBuffer();
String regex = "\\\\([0-9a-fA-F]{4})";
// Compile the regex
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
// Find all matches and replace them with the decoded character
while (matcher.find()) {
String hexValue = matcher.group(1);
int unicodeValue = Integer.parseInt(hexValue, 16);
matcher.appendReplacement(decodedString, String.valueOf((char) unicodeValue));
}
matcher.appendTail(decodedString);
return decodedString.toString().replaceAll("\\\\", "");
StringBuffer decodedString = new StringBuffer();
String regex = "\\\\([0-9a-fA-F]{4})";
// Compile the regex
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);

// Find all matches and replace them with the decoded character
while (matcher.find()) {
String hexValue = matcher.group(1);
int unicodeValue = Integer.parseInt(hexValue, 16);
matcher.appendReplacement(decodedString, String.valueOf((char) unicodeValue));
}
matcher.appendTail(decodedString);
return decodedString.toString().replaceAll("\\\\", "");
} catch (Exception e) {
// If decoding fails, just return the original string
return input;
}
}

/**
* This is where the magic lives.
*
Expand Down

0 comments on commit 3c29524

Please sign in to comment.