Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix/jsonld-document…
Browse files Browse the repository at this point in the history
…-loader-node18
  • Loading branch information
TimoGlastra committed Jun 15, 2023
2 parents 215d083 + 38a0578 commit 9b08884
Showing 1 changed file with 9 additions and 4 deletions.
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
}
}

0 comments on commit 9b08884

Please sign in to comment.