itinance / itinance/react-native-fs

[Android] assetExistsRes doesn't check for extension

Open
#665 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

`assetExistsRes` breaks if you give it a file without extension with an index out of range error. The bug is [here](https://github.com/itinance/react-native-fs/blob/57b6131aaad5b7721857b9bf24dc86d8bcaf6eda/android/src/main/java/com/rnfs/RNFSManager.java):

```
private int getResIdentifier(String filename) {
String suffix = filename.substring(filename.lastIndexOf(".") + 1);
String name = filename.substring(0, filename.lastIndexOf("."));
// ...
}
```

The function should probably check that index before feeding it to `.substring`, and on that note it might be nice to provide an example of how to use `assetExistsRes` since users usually interact with files in `res` by removing the extension, it definitely isn't obvious that you have to give it the filename with extension.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.