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

fix: check if URL already encoded #1485

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/react-native/src/ReactNativeFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ export class ReactNativeFileSystem implements FileSystem {
// Make sure parent directories exist
await RNFS.mkdir(getDirFromFilePath(path))

// Some characters in the URL might be invalid for
// the native os to handle. We need to encode the URL.
const encodedFromUrl = encodeURI(url)
const fromUrl = this.encodeUriIfRequired(url)

const { promise } = RNFS.downloadFile({
fromUrl: encodedFromUrl,
fromUrl,
toFile: path,
})

Expand All @@ -92,4 +91,10 @@ export class ReactNativeFileSystem implements FileSystem {
}
}
}

private encodeUriIfRequired(uri: string) {
// Some characters in the URL might be invalid for
// the native os to handle. Only encode if necessary.
return uri === decodeURI(uri) ? encodeURI(uri) : uri
}
}