okhttp3 3.12.x parse Part BUG

Created on 17 Jan 2019  Â·  8Comments  Â·  Source: square/okhttp

Good bug reports include a failing test! Writing a test helps you to isolate and describe the problem, and it helps us to fix it fast. Bug reports without a failing test or reproduction steps are likely to be closed.

Here’s an example test to get you started.
https://gist.github.com/swankjesse/981fcae102f513eb13ed

Version :

3.12.x

Error description :

When the MultipartBody.Part.createFormData(String name, @Nullable String filename, RequestBody body) method is called, if the file name contains Chinese, an IllegalArgumentException will be thrown to locate the calling chain:

MultipartBody.Part.createFormData(String name, @Nullable String filename, RequestBody body) 
Headers.of(String... namesAndValues)
Headers.checkValue(String value, String name)

The final code is as follows:

  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));
      }
    }
  }

As shown above, this code does not handle Chinese correctly.

bug

Most helpful comment

Is it possible to backport this to 3.12.x?

All 8 comments

@swankjesse

Related to https://github.com/square/okhttp/issues/3876

Should confirm we got all cases.

Is it possible to backport this to 3.12.x?

@valepakh pull request?

@swankjesse my application support android4.x but this bug very critical
can't send multipart Korean file name
need backport this to 3.12.x

@Movill-Tony-p awesome. Please do.

@swankjesse I actually filed pull request #4618 a while back, it works ok, just doesn't pass the build due to the java changes.

Thanks so much for this backport, @valepakh, and for the merge, @swankjesse. You're helping folks collect data in challenging environments (and languages with Unicode characters). 🎉

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dannyZhou picture dannyZhou  Â·  3Comments

yschimke picture yschimke  Â·  3Comments

yschimke picture yschimke  Â·  3Comments

lyf571321556 picture lyf571321556  Â·  3Comments

vanshg picture vanshg  Â·  3Comments