From 67e18b4fa3c6fbb0d4b56fa032addf6a55d9e1ad Mon Sep 17 00:00:00 2001 From: jiangtd Date: Sat, 6 Jun 2026 02:25:07 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E4=BA=86=E5=AF=B9base64?= =?UTF-8?q?=E7=9A=84urlecode=E7=9A=84=E6=95=B0=E6=8D=AE=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../com/heyu/api/data/utils/ImageInputUtils.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c834f41..6e7f1a4 100644 --- a/.gitignore +++ b/.gitignore @@ -268,3 +268,4 @@ build /.codebuddy/rules/编码规则.mdc CLAUDE.local.md /docs/ +/AGENTS.md diff --git a/api-mapper/src/main/java/com/heyu/api/data/utils/ImageInputUtils.java b/api-mapper/src/main/java/com/heyu/api/data/utils/ImageInputUtils.java index d6ca99d..740e990 100644 --- a/api-mapper/src/main/java/com/heyu/api/data/utils/ImageInputUtils.java +++ b/api-mapper/src/main/java/com/heyu/api/data/utils/ImageInputUtils.java @@ -213,7 +213,8 @@ public final class ImageInputUtils { } private static ValidationResult validateBase64(String trimmed) { - if (trimmed.regionMatches(true, 0, "data:", 0, 5) && trimmed.indexOf("base64,") < 0) { + String decodedInput = tryUrlDecode(trimmed).trim(); + if (decodedInput.regionMatches(true, 0, "data:", 0, 5) && indexOfIgnoreCase(decodedInput, "base64,") < 0) { return ValidationResult.fail( "Base64 前缀无效", "data: 前缀格式不正确,缺少 base64, 段", @@ -221,7 +222,7 @@ public final class ImageInputUtils { "入参前缀=" + abbreviate(trimmed, 48) ); } - String missingSchemeHint = diagnoseMissingUrlScheme(trimmed); + String missingSchemeHint = diagnoseMissingUrlScheme(decodedInput); if (missingSchemeHint != null) { return ValidationResult.fail( "链接缺少协议头", @@ -231,7 +232,7 @@ public final class ImageInputUtils { ); } - String rawBase64 = stripDataUriPrefix(trimmed); + String rawBase64 = stripDataUriPrefix(decodedInput); String normalized = rawBase64.replaceAll("\\s+", ""); if (normalized.length() < 4) { return ValidationResult.fail( @@ -378,13 +379,17 @@ public final class ImageInputUtils { if (!input.regionMatches(true, 0, "data:", 0, 5)) { return input; } - int base64Idx = input.indexOf("base64,"); + int base64Idx = indexOfIgnoreCase(input, "base64,"); if (base64Idx >= 0) { return input.substring(base64Idx + "base64,".length()); } return input; } + private static int indexOfIgnoreCase(String text, String search) { + return text.toLowerCase().indexOf(search.toLowerCase()); + } + /** * 若入参尚未做表单 urlencode,则进行编码;已编码则原样返回。 */