fix: 统一工作流空媒体参数处理

This commit is contained in:
2026-08-31 15:00:49 +08:00
parent a771affc5d
commit 1d3147e7bf
5 changed files with 146 additions and 22 deletions

View File

@@ -139,7 +139,7 @@ public class WorkflowRunningParameterResolver {
}
/**
* 归一化工作流运行时变量,确保文件参数统一文件对象数组
* 归一化工作流运行时变量,统一文件结构并移除空图片值
*
* @param content 工作流内容
* @param variables 原始运行变量
@@ -162,7 +162,13 @@ public class WorkflowRunningParameterResolver {
if (isFileParameter(parameter)) {
normalized.put(name, normalizeFileVariableValue(normalized.get(name), name));
} else if (isImageParameter(parameter)) {
normalized.put(name, normalizeImageVariableValue(normalized.get(name), name));
Object imageValue = normalizeImageVariableValue(
normalized.get(name), name);
if (imageValue == null) {
normalized.remove(name);
} else {
normalized.put(name, imageValue);
}
}
}
return normalized;
@@ -683,6 +689,10 @@ public class WorkflowRunningParameterResolver {
if (value == null) {
return;
}
if (value instanceof String stringValue
&& !StringUtils.hasText(stringValue)) {
return;
}
if (value instanceof Collection<?> collection) {
for (Object item : collection) {
collectFileValues(item, result);

View File

@@ -219,6 +219,38 @@ public class WorkflowRunningParameterResolverTest {
Assert.assertTrue(((List<?>) attachments).get(0) instanceof Map<?, ?>);
}
/**
* 空文件参数应统一归一化为空数组,避免旧客户端空字符串触发格式错误。
*
* @throws Exception 反射注入失败
*/
@Test
public void testNormalizeRuntimeVariablesShouldTreatBlankFileValuesAsEmptyList()
throws Exception {
WorkflowRunningParameterResolver resolver = newResolver();
Object[] emptyValues = {null, "", " ", List.of()};
for (Object emptyValue : emptyValues) {
Map<String, Object> variables = new LinkedHashMap<>();
variables.put("attachments", emptyValue);
Map<String, Object> normalized = resolver.normalizeRuntimeVariables(
workflowContentWithStartParameters(),
variables);
Assert.assertEquals(List.of(), normalized.get("attachments"));
}
Map<String, Object> variables = new LinkedHashMap<>();
variables.put("attachments", List.of(
" ",
"https://files.example.com/contracts/contract.docx"));
List<?> normalizedFiles = (List<?>) resolver.normalizeRuntimeVariables(
workflowContentWithStartParameters(),
variables).get("attachments");
Assert.assertEquals(1, normalizedFiles.size());
}
/**
* 文件参数应接受远程 URL 字符串数组并自动提取文件名。
*
@@ -446,6 +478,30 @@ public class WorkflowRunningParameterResolverTest {
Assert.assertEquals("https://example.com/image.png", image.get("url"));
}
/**
* 空图片参数应从运行变量中移除,避免向执行引擎的并发 Map 写入 null。
*
* @throws Exception 反射注入失败
*/
@Test
public void testNormalizeRuntimeVariablesShouldRemoveBlankImageValues()
throws Exception {
WorkflowRunningParameterResolver resolver = newResolver();
Object[] emptyValues = {null, "", " "};
for (Object emptyValue : emptyValues) {
Map<String, Object> variables = new LinkedHashMap<>();
variables.put("image_input", emptyValue);
Map<String, Object> normalized = resolver.normalizeRuntimeVariables(
workflowContentWithImageStartParameter(),
variables);
Assert.assertFalse(normalized.containsKey("image_input"));
Assert.assertFalse(normalized.containsValue(null));
}
}
/**
* 运行入口不应接收 Data URI避免 Base64 写入工作流状态和审计参数。
*