【Android】okhttp使用3.12.12,特殊字符(如中文)文件名会导致Crash~
- Dominant language
- Java
- Stars
- 20.4k
- Forks
- 3.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 2
Description
**Crash stack info**
java.lang.IllegalArgumentException: Unexpected char 0xb6 at 99 in savePath value: /data/user/0/com.xxx.xxx/files/8895971331/DownloadFolder/platform/MmsAttachment/67479015553726/¶¯Í¼-3%20.gif
at okhttp3.Headers.checkValue(Headers.java:272)
at okhttp3.Headers$Builder.add(Headers.java:312)
at com.didichuxing.doraemonkit.aop.urlconnection.ObsoleteUrlFactory$OkHttpURLConnection.addRequestProperty(ObsoleteUrlFactory.java:708)
at com.didichuxing.doraemonkit.aop.urlconnection.ObsoleteUrlFactory$DelegatingHttpsURLConnection.addRequestProperty(ObsoleteUrlFactory.java:1112)
**Device info**
Android 11, pixel 3
**Other**
通过okhttp3.12.12源码可以发现,如果文件包含特殊字符(比如中文)就抛异常,但是在上一层函数中并没有捕获和进一步往上throw:
```java
public Builder add(String name, String value) {
checkName(name);
checkValue(value, name);
return addLenient(name, value);
}
static void checkValue(String value, String name) {
if (value == null) throw new NullPointerException("value for name " + name + " == null");
for (int i = 0, length = value.length(); i < length; i++) {
char c = value.charAt(i);
if ((c <= '\u001f' && c != '\t') || c >= '\u007f') {
throw new IllegalArgumentException(Util.format(
"Unexpected char %#04x at %d in %s value: %s", (int) c, i, name, value));
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.