react-native: Android 4.4.4 axios JSON.parse(response) error

Environment

System:
  OS: macOS High Sierra 10.13.3
  CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  Memory: 94.82 MB / 16.00 GB
  Shell: 3.2.57 - /bin/bash
Binaries:
  Node: 8.11.4 - ~/.nvm/versions/node/v8.11.4/bin/node
  npm: 5.6.0 - ~/.nvm/versions/node/v8.11.4/bin/npm
  Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
  iOS SDK:
    Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
  Android SDK:
    Build Tools: 19.1.0, 20.0.0, 21.1.1, 21.1.2, 22.0.0, 22.0.1, 23.0.0, 23.0.1, 23.0.2, 23.0.3, 24.0.0, 24.0.1, 24.0.2, 24.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.1, 27.0.2, 27.0.3, 28.0.2
    API Levels: 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27
IDEs:
  Android Studio: 3.1 AI-173.4907809
  Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
npmPackages:
  react: 16.4.1 => 16.4.1
  react-native: 0.56.0 => 0.56.0
npmGlobalPackages:
  react-native-git-upgrade: 0.2.7

Description

On Android 4.4.4,when response body is too big(~20kb), response body will cut the content and JSON.parse(response) will occur the SyntaxError: Unexpected token i in JSON at position. I print the request body, and this content like this: {"id":1,"name":""isRequired":1}, the content after name lose the value",. The complete content should be {"id":1,"name":"value","isRequired":1}.

I also set maxContentLength: Number.MAX_VALUE, but it’s not work.

I using react native v0.56.0 and axios v0.18.0.

I also tried Fetch and it’s work.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 34 (13 by maintainers)

Most upvoted comments

@TareqElMasri, I had no PR that fixes your problem and my original PR doesn’t have the old code anymore. I took a moment today to implement the fix you guys asking for in this thread. If it helps I could make a PR. The fix is in this branch: https://github.com/dryganets/react-native/tree/sergeyd/android-progressive-decoding-kitkat-compat

I also fixed the IDE support for UnitTests for your convenience.

ProgressiveStringDecoderTest will be a good place to reproduce the original KitKat issue. ProgressiveUTF8StringDecoderTest testing the class used for KitKat.

So, you basically need to have a data sample which fails the ProgressiveStringDecoderTest and works with ProgressiveUTF8StringDecoderTest on KitKat to verify that fix is working.

me too

Valid json key is string, so id should be “id”, maybe it’s the problem. Can you check this ?