Add HTML sanitizer for translated message resources#4
Conversation
Closes #37428 Signed-off-by: Alexander Schwartz <alexander.schwartz@gmx.net>
| while (end < sanitized.length() && end < value.length() && value.charAt(value.length() - end - 1) == sanitized.charAt(sanitized.length() - end - 1)) { | ||
| end++; | ||
| } | ||
|
|
There was a problem hiding this comment.
| ```suggestion | |
| int endValue = Math.max(start, value.length() - end); | |
| int endSanitized = Math.max(start, sanitized.length() - end); | |
| messages.add("Illegal HTML in key " + key + " for file " + file + ": '" | |
| + value.substring(start, endValue) + "' vs. '" | |
| + sanitized.substring(start, endSanitized) + "'"); |
| try (FileInputStream fis = new FileInputStream(file)) { | ||
| bundle = new PropertyResourceBundle(fis); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException("unable to read file " + file, e); |
There was a problem hiding this comment.
🔷 Medium: The character class "[a-zA-Z-_]" creates an unintended range (Z to _) due to '-' placement, which may over-match. Also, anchoring to the end avoids accidental replacements earlier in the path.
| throw new RuntimeException("unable to read file " + file, e); | |
| ```suggestion | |
| String englishFile = file.getAbsolutePath() | |
| .replace("resources-community", "resources") | |
| .replaceFirst("_[A-Za-z_-]*\\.properties$", "_en.properties"); |
|
|
||
| /** | ||
| * Allow only those anchor tags from the source key to also appear in the target key. | ||
| */ |
There was a problem hiding this comment.
🔷 Medium: The method mutates 'value' inside a loop driven by a Matcher created from the original 'value'; since Matcher operates on the original CharSequence, subsequent replacements can desynchronize matching and produce incorrect removals with multiple anchors. Use the Matcher to perform replacements via appendReplacement/appendTail so the match context stays consistent.
suggestion
private String santizeAnchors(String key, String value, String englishValue) {
Matcher matcher = ANCHOR_PATTERN.matcher(value);
Matcher englishMatcher = ANCHOR_PATTERN.matcher(englishValue);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
if (englishMatcher.find() && Objects.equals(matcher.group(), englishMatcher.group())) {
matcher.appendReplacement(sb, "");
} else {
messages.add("Didn't find anchor tag " + matcher.group() + " in original string");
return value;
}
}
matcher.appendTail(sb);
return sb.toString();
}
| configureAuthenticators=Sukonfigūruotas autentifikatorius | ||
| mobile=Mobilus | ||
| totpStep1=Įdiekite <a href="https://freeotp.github.io/" target="_blank">FreeOTP</a> arba Google Authenticator savo įrenginyje. Programėlės prieinamos <a href="https://play.google.com">Google Play</a> ir Apple App Store. | ||
| totpStep1=Installa una delle seguenti applicazioni sul tuo cellulare: |
There was a problem hiding this comment.
| totpStep1=Installa una delle seguenti applicazioni sul tuo cellulare: | |
| totpStep1=Įdiekite FreeOTP arba Google Authenticator savo įrenginyje. Programėlės prieinamos Google Play ir Apple App Store. |
| configureAuthenticators=配置的认证者 | ||
| mobile=手机 | ||
| totpStep1=在你的设备上安装 <a href="https://fedorahosted.org/freeotp/" target="_blank">FreeOTP</a> 或者 Google Authenticator.两个应用可以从 <a href="https://play.google.com">Google Play</a> 和 Apple App Store下载。 | ||
| totpStep1=在您的手機上安裝以下應用程式之一: |
There was a problem hiding this comment.
🔷 Medium: This is Traditional Chinese text in a Simplified Chinese file (zh_CN). Use Simplified characters to avoid inconsistency and confusion.
| totpStep1=在您的手機上安裝以下應用程式之一: | |
| totpStep1=在您的手机上安装以下应用之一: |
No description provided.