fix(items): Locale.ROOT case-folding + document sanitize cap unit + tighten cap test

This commit is contained in:
simoleo89
2026-06-04 21:01:16 +02:00
parent 5bf1d42cfb
commit 28c3e93945
2 changed files with 9 additions and 3 deletions
@@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
@@ -47,11 +48,16 @@ public class FurnitureTextProvider {
if (classname == null) return null;
int star = classname.indexOf('*');
String base = (star >= 0) ? classname.substring(0, star) : classname;
base = base.trim().toLowerCase();
base = base.trim().toLowerCase(Locale.ROOT);
return base.isEmpty() ? null : base;
}
/** Cap length, strip control chars/newlines, neutralize % (placeholder-injection safe). */
/**
* Cap length, strip control chars/newlines, neutralize % (placeholder-injection safe).
* The 256 cap is in Java {@code char} units (UTF-16 code units), which is acceptable for
* furni names (controlled, predominantly ASCII source). Lone/astral surrogates are not
* specially handled.
*/
static String sanitize(String value) {
if (value == null) return "";
StringBuilder sb = new StringBuilder(Math.min(value.length(), MAX_LEN));
@@ -47,7 +47,7 @@ class FurnitureTextProviderTest {
FurnitureTextProvider p = provider(true,
new FurnidataEntry(1, "x", FurnitureType.FLOOR, evil, ""));
String name = p.getName("x");
assertTrue(name.length() <= 256, "must be capped to 256");
assertEquals(256, name.length(), "input far exceeds the cap, so it must be exactly 256");
assertFalse(name.chars().anyMatch(Character::isISOControl), "no control chars remain after sanitize");
assertFalse(name.contains("%"), "ASCII percent neutralized");
}