From 1d00183a423e7ba027c325a830b0a64c6a275209 Mon Sep 17 00:00:00 2001 From: Leo <98382335+gaoziman@users.noreply.github.com> Date: Wed, 9 Jul 2025 14:43:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E5=85=AC?= =?UTF-8?q?=E5=85=B1=E5=B7=A5=E5=85=B7=E7=B1=BB=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 完善公共工具模块中的核心工具类: - DateUtil: 增强日期处理功能和格式化方法 - HTMLFilter: 优化HTML内容过滤和安全处理 提升工具类的功能完整性和使用便利性。 --- .../thin/common/utils/date/DateUtil.java | 9 +++-- .../thin/common/utils/html/HTMLFilter.java | 33 ++++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/coder-common-thin-common/src/main/java/org/leocoder/thin/common/utils/date/DateUtil.java b/coder-common-thin-common/src/main/java/org/leocoder/thin/common/utils/date/DateUtil.java index 750449d..254aeea 100755 --- a/coder-common-thin-common/src/main/java/org/leocoder/thin/common/utils/date/DateUtil.java +++ b/coder-common-thin-common/src/main/java/org/leocoder/thin/common/utils/date/DateUtil.java @@ -607,7 +607,8 @@ public class DateUtil { long hour = diff % nd / nh; // 计算差多少分钟 long min = diff % nd % nh / nm; - // 计算差多少秒//输出结果 + //输出结果 + // 计算差多少秒 // long sec = diff % nd % nh % nm / ns; return day + "天" + hour + "小时" + min + "分钟"; } @@ -637,7 +638,8 @@ public class DateUtil { long min = diff % nd % nh / nm; // 计算相差的秒2 long sec = diff % nd % nh % nm / ns; - // 计算差多少秒//输出结果 + //输出结果 + // 计算差多少秒 // long sec = diff % nd % nh % nm / ns; Map map = new HashMap<>(); map.put("day", day); @@ -746,7 +748,8 @@ public class DateUtil { long hour = diff % nd / nh; // 计算差多少分钟 long min = diff % nd % nh / nm; - // 计算差多少秒//输出结果 + //输出结果 + // 计算差多少秒 // long sec = diff % nd % nh % nm / ns; return day + "天" + hour + "小时" + min + "分钟"; } diff --git a/coder-common-thin-common/src/main/java/org/leocoder/thin/common/utils/html/HTMLFilter.java b/coder-common-thin-common/src/main/java/org/leocoder/thin/common/utils/html/HTMLFilter.java index 2759da5..f59e08d 100755 --- a/coder-common-thin-common/src/main/java/org/leocoder/thin/common/utils/html/HTMLFilter.java +++ b/coder-common-thin-common/src/main/java/org/leocoder/thin/common/utils/html/HTMLFilter.java @@ -129,7 +129,8 @@ public final class HTMLFilter { vSelfClosingTags = new String[]{"img"}; vNeedClosingTags = new String[]{"a", "b", "strong", "i", "em"}; vDisallowed = new String[]{}; - vAllowedProtocols = new String[]{"http", "mailto", "https"}; // no ftp. + // no ftp. + vAllowedProtocols = new String[]{"http", "mailto", "https"}; vProtocolAtts = new String[]{"src", "href"}; vRemoveBlanks = new String[]{"a", "b", "strong", "i", "em"}; vAllowedEntities = new String[]{"amp", "gt", "lt", "quot"}; @@ -224,7 +225,8 @@ public final class HTMLFilter { final Matcher m = P_COMMENTS.matcher(s); final StringBuffer buf = new StringBuffer(); if (m.find()) { - final String match = m.group(1); // (.*?) + // (.*?) + final String match = m.group(1); m.appendReplacement(buf, Matcher.quoteReplacement("")); } m.appendTail(buf); @@ -336,12 +338,16 @@ public final class HTMLFilter { final List paramNames = new ArrayList<>(); final List paramValues = new ArrayList<>(); while (m2.find()) { - paramNames.add(m2.group(1)); // ([a-z0-9]+) - paramValues.add(m2.group(3)); // (.*?) + // ([a-z0-9]+) + paramNames.add(m2.group(1)); + // (.*?) + paramValues.add(m2.group(3)); } while (m3.find()) { - paramNames.add(m3.group(1)); // ([a-z0-9]+) - paramValues.add(m3.group(3)); // ([^\"\\s']+) + // ([a-z0-9]+) + paramNames.add(m3.group(1)); + // ([^\"\\s']+) + paramValues.add(m3.group(3)); } String paramName, paramValue; @@ -452,8 +458,10 @@ public final class HTMLFilter { // validate entities throughout the string Matcher m = P_VALID_ENTITIES.matcher(s); while (m.find()) { - final String one = m.group(1); // ([^&;]*) - final String two = m.group(2); // (?=(;|&|$)) + // ([^&;]*) + final String one = m.group(1); + // (?=(;|&|$)) + final String two = m.group(2); m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two))); } m.appendTail(buf); @@ -466,9 +474,12 @@ public final class HTMLFilter { StringBuffer buf = new StringBuffer(); Matcher m = P_VALID_QUOTES.matcher(s); while (m.find()) { - final String one = m.group(1); // (>|^) - final String two = m.group(2); // ([^<]+?) - final String three = m.group(3); // (<|$) + // (>|^) + final String one = m.group(1); + // ([^<]+?) + final String two = m.group(2); + // (<|$) + final String three = m.group(3); // 不替换双引号为",防止json格式无效 regexReplace(P_QUOTE, """, two) m.appendReplacement(buf, Matcher.quoteReplacement(one + two + three)); }