Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling mergeItem with a json array crashes the app #699

Open
1 of 5 tasks
zhuangdaz opened this issue Oct 27, 2021 · 7 comments
Open
1 of 5 tasks

Calling mergeItem with a json array crashes the app #699

zhuangdaz opened this issue Oct 27, 2021 · 7 comments
Labels
bug Something isn't working help wanted :octocat:

Comments

@zhuangdaz
Copy link

zhuangdaz commented Oct 27, 2021

What happened?

I created an array of users and then tried to update one of the user by passing a new JSON array string. Then the app crashes.

const USER_1 = {
  name: "Tom",
  age: 20,
  traits: {
    hair: "black",
    eyes: "blue",
  },
};

const USER_2 = {
  name: "Sarah",
  age: 21,
  hobby: "cars",
  traits: {
    eyes: "green",
  },
};

const USER_3 = {
  name: "Sarah",
  age: 22,
  hobby: "bike",
  traits: {
    eyes: "green",
  },
};

const USERS = [USER_1, USER_2];

const mergeUsers = async () => {
  try {
    console.log("creating users");
    await AsyncStorage.setItem("@MyApp_users", JSON.stringify(USERS));

    console.log("merging user 3");
    await AsyncStorage.mergeItem("@MyApp_users", JSON.stringify([USER_3]));

    // read merged item
    console.log("reading merged users");
    const currentUsers = await AsyncStorage.getItem("@MyApp_users");
    console.log(currentUsers);
  } catch (err) {}
};

Version

1.15.0

What platforms are you seeing this issue on?

  • Android
  • iOS
  • macOS
  • Windows
  • web

System Information

info Fetching system and libraries information...
System:
    OS: macOS 11.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
    Memory: 473.64 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: 1.22.15 - /usr/local/bin/yarn
    npm: 8.1.0 - /usr/local/bin/npm
    Watchman: 2021.10.04.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: Not Found
  SDKs:
    iOS SDK: Not Found
    Android SDK: Not Found
  IDEs:
    Android Studio: 1.3 AI-141.2135290
    Xcode: /undefined - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.10 - /Users/zhuangda/.jenv/shims/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: ^17.0.2 => 17.0.2 
    react-native: 0.64.2 => 0.64.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to Reproduce

Described above.

@zhuangdaz zhuangdaz added the bug Something isn't working label Oct 27, 2021
@krizzu
Copy link
Member

krizzu commented Nov 24, 2021

Hey @zhuangdaz

Thanks for reporting that. After a quick check, it's indeed a bug. It's located here. This method is responsible for merging two objects. Those allegedly should be NSDictionaries, while in truth, they're NSArrays. The crash happens when reading a value for a key.

@EddyKay101
Copy link

Hi, any update on this please as I am experiencing the same issue.

Thanks

@acer1456
Copy link

any updates on this bug? got the same issue too.

thanks

@gonzalopantoja
Copy link

gonzalopantoja commented Feb 21, 2022

Hi I'm running into this issue, is there any update?

Here are the versions I tested:
version 1.13.2 - no issue
version 1.14.1 - no issue
version 1.15.15 - issue
version 1.16.1 (latest) - issue

@krizzu
Copy link
Member

krizzu commented Feb 24, 2022

Hey

@gonzalopantoja thanks for pointing this out, this should come helpful to see where regression happened 🙏

I'm trying to find a time to address this, but in the mean time, happy to accept a PR, as always 😄

@github-actions
Copy link

This issue has been marked as stale due to inactivity. Please respond or otherwise resolve the issue within 7 days or it will be closed.

@sabinayakc
Copy link

I am experiencing this issue as well with the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted :octocat:
Projects
None yet
Development

No branches or pull requests

7 participants