修正 Raw 图片输出格式回退
忽略空值后再使用载荷级格式 补充空字符串和 null 回归测试
This commit is contained in:
@@ -366,10 +366,16 @@ fn response_image_format(
|
||||
) -> Result<(&'static str, &'static str), &'static str> {
|
||||
let Some(value) = entry
|
||||
.get("output_format")
|
||||
.or_else(|| payload.get("output_format"))
|
||||
.and_then(Value::as_str)
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.or_else(|| {
|
||||
payload
|
||||
.get("output_format")
|
||||
.and_then(Value::as_str)
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
})
|
||||
else {
|
||||
return Err("上游响应缺少 output_format");
|
||||
};
|
||||
@@ -455,6 +461,20 @@ mod tests {
|
||||
response_image_format(&json!({}), &json!({"output_format": "jpeg"})),
|
||||
Ok(("image/jpeg", "jpg"))
|
||||
);
|
||||
assert_eq!(
|
||||
response_image_format(
|
||||
&json!({"output_format": "png"}),
|
||||
&json!({"output_format": ""})
|
||||
),
|
||||
Ok(("image/png", "png"))
|
||||
);
|
||||
assert_eq!(
|
||||
response_image_format(
|
||||
&json!({"output_format": "webp"}),
|
||||
&json!({"output_format": null})
|
||||
),
|
||||
Ok(("image/webp", "webp"))
|
||||
);
|
||||
assert!(response_image_format(&json!({}), &json!({})).is_err());
|
||||
assert!(response_image_format(&json!({}), &json!({"output_format": "bmp"})).is_err());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user