1.修改了对base64的urlecode的数据报错的问题
This commit is contained in:
parent
1ff0df6cdb
commit
67e18b4fa3
1
.gitignore
vendored
1
.gitignore
vendored
@ -268,3 +268,4 @@ build
|
|||||||
/.codebuddy/rules/编码规则.mdc
|
/.codebuddy/rules/编码规则.mdc
|
||||||
CLAUDE.local.md
|
CLAUDE.local.md
|
||||||
/docs/
|
/docs/
|
||||||
|
/AGENTS.md
|
||||||
|
|||||||
@ -213,7 +213,8 @@ public final class ImageInputUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ValidationResult validateBase64(String trimmed) {
|
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(
|
return ValidationResult.fail(
|
||||||
"Base64 前缀无效",
|
"Base64 前缀无效",
|
||||||
"data: 前缀格式不正确,缺少 base64, 段",
|
"data: 前缀格式不正确,缺少 base64, 段",
|
||||||
@ -221,7 +222,7 @@ public final class ImageInputUtils {
|
|||||||
"入参前缀=" + abbreviate(trimmed, 48)
|
"入参前缀=" + abbreviate(trimmed, 48)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
String missingSchemeHint = diagnoseMissingUrlScheme(trimmed);
|
String missingSchemeHint = diagnoseMissingUrlScheme(decodedInput);
|
||||||
if (missingSchemeHint != null) {
|
if (missingSchemeHint != null) {
|
||||||
return ValidationResult.fail(
|
return ValidationResult.fail(
|
||||||
"链接缺少协议头",
|
"链接缺少协议头",
|
||||||
@ -231,7 +232,7 @@ public final class ImageInputUtils {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String rawBase64 = stripDataUriPrefix(trimmed);
|
String rawBase64 = stripDataUriPrefix(decodedInput);
|
||||||
String normalized = rawBase64.replaceAll("\\s+", "");
|
String normalized = rawBase64.replaceAll("\\s+", "");
|
||||||
if (normalized.length() < 4) {
|
if (normalized.length() < 4) {
|
||||||
return ValidationResult.fail(
|
return ValidationResult.fail(
|
||||||
@ -378,13 +379,17 @@ public final class ImageInputUtils {
|
|||||||
if (!input.regionMatches(true, 0, "data:", 0, 5)) {
|
if (!input.regionMatches(true, 0, "data:", 0, 5)) {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
int base64Idx = input.indexOf("base64,");
|
int base64Idx = indexOfIgnoreCase(input, "base64,");
|
||||||
if (base64Idx >= 0) {
|
if (base64Idx >= 0) {
|
||||||
return input.substring(base64Idx + "base64,".length());
|
return input.substring(base64Idx + "base64,".length());
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int indexOfIgnoreCase(String text, String search) {
|
||||||
|
return text.toLowerCase().indexOf(search.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 若入参尚未做表单 urlencode,则进行编码;已编码则原样返回。
|
* 若入参尚未做表单 urlencode,则进行编码;已编码则原样返回。
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user