itinance / itinance/react-native-fs
RNFS.TemporaryDirectoryPath trailing `/` behavior differs on Android vs. iOS
- Dominant language
- C++
- Stars
- 5k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
When evaluating `RNFS.TemporaryDirectoryPath`, on Android, the file path output does not include a trailing slash. On a local simulator, e.g., it outputs this:
`/data/user/0/com.example.app/cache`
On iOS, on the other hand, the output DOES contain a trailing slash--like this:
`/Users//Library/Developer/CoreSimulator/Devices//data/Containers/Data/Application//tmp/`
Now, oddly, when I include a separating slash, such as this:
```
const filePath = `${RNFS.TemporaryDirectoryPath}/filename.png
console.log(filePath); // iOS output: ...Application//tmp//c50caef6-3303-600d-f85a-887a9e5de3f3.zip
```
It does work on both platforms. Perhaps RNFS has some transforming operations when it detects two `//` paired together? Or perhaps this is at the OS level.
Still, this feels unsafe--there's really no telling when some other library may not handle this properly.
**Suggested fix:** remove the trailing slash from the iOS output on `TemporaryDirectoryPath`. This makes for the most natural string construction (`${TemporaryDirectoryPath}/${filename}`--note the separating slash) and preserves existing code that seems to be working in many projects.
Note that this may be a breaking change for folks who are relying on this inconsistent output.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.