修复中文文件名直传签名失败

在 OSS 文件名清洗中为空主体使用 file 兜底

补充中文文件名清洗回归测试
This commit is contained in:
2026-06-27 22:36:15 +08:00
parent 5976c2b337
commit d31cac8cbc
+13 -3
View File
@@ -1182,9 +1182,11 @@ fn sanitize_file_name(raw: &str) -> Result<String, OssError> {
.collect::<String>();
let stem = collapse_dashes(&stem);
if stem.is_empty() {
return Err(OssError::InvalidRequest("fileName 主体不合法".to_string()));
}
let stem = if stem.is_empty() {
"file".to_string()
} else {
stem
};
let extension = raw_extension
.map(|extension| {
@@ -1767,6 +1769,14 @@ mod tests {
);
}
#[test]
fn sanitize_file_name_falls_back_when_stem_has_no_ascii_body() {
assert_eq!(
sanitize_file_name("剪贴板素材.png").expect("file name should sanitize"),
"file.png"
);
}
#[test]
fn sign_get_object_url_returns_signed_private_read_url() {
let client = build_client();