Check if html files contain non ASCII characters.

This commit is contained in:
MobiusDevelopment
2020-02-08 02:41:23 +00:00
parent 0ed057dff9
commit 71576ed8af
714 changed files with 1240 additions and 1179 deletions

View File

@@ -474,6 +474,7 @@ public class Config
public static boolean MULTIPLE_ITEM_DROP;
public static boolean FORCE_INVENTORY_UPDATE;
public static boolean LAZY_CACHE;
public static boolean CHECK_HTML_ENCODING;
public static boolean CACHE_CHAR_NAMES;
public static int MIN_NPC_ANIMATION;
public static int MAX_NPC_ANIMATION;
@@ -1943,6 +1944,7 @@ public class Config
MULTIPLE_ITEM_DROP = General.getBoolean("MultipleItemDrop", true);
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
LAZY_CACHE = General.getBoolean("LazyCache", true);
CHECK_HTML_ENCODING = General.getBoolean("CheckHtmlEncoding", true);
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
@@ -3143,6 +3145,10 @@ public class Config
MULTILANG_DEFAULT = MultilingualSupport.getString("MultiLangDefault", "en").toLowerCase();
MULTILANG_ENABLE = MultilingualSupport.getBoolean("MultiLangEnable", false);
if (MULTILANG_ENABLE)
{
CHECK_HTML_ENCODING = false;
}
final String[] allowed = MultilingualSupport.getString("MultiLangAllowed", MULTILANG_DEFAULT).split(";");
MULTILANG_ALLOWED = new ArrayList<>(allowed.length);
for (String lang : allowed)

View File

@@ -115,6 +115,7 @@ public class HtmCache
return null;
}
String filePath = null;
String content = null;
try (FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis))
@@ -126,7 +127,13 @@ public class HtmCache
content = new String(raw, StandardCharsets.UTF_8);
content = content.replaceAll("(?s)<!--.*?-->", ""); // Remove html comments
final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
filePath = file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length());
if (Config.CHECK_HTML_ENCODING && !filePath.startsWith("data/lang") && !StandardCharsets.US_ASCII.newEncoder().canEncode(content))
{
LOGGER.warning("HTML encoding check: File " + filePath + " contains non ASCII content.");
}
final String oldContent = HTML_CACHE.put(filePath, content);
if (oldContent == null)
{
_bytesBuffLen += bytes;