From b509235fb7743fd2753d07a1ac6a321966022a94 Mon Sep 17 00:00:00 2001 From: Ngoc Le Date: Sat, 22 Aug 2026 18:27:24 +0700 Subject: [PATCH] fix(android): preserve encoded content URIs --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 50d437a9..73b34cc7 100644 --- a/index.js +++ b/index.js @@ -255,6 +255,7 @@ export default class Pdf extends Component { const isNetwork = !!(uri && uri.match(/^https?:\/\//)); const isAsset = !!(uri && uri.match(/^bundle-assets:\/\//)); const isBase64 = !!(uri && uri.match(/^data:application\/pdf;base64/)); + const isContentUri = !!(uri && uri.match(/^content:\/\//i)); const filename = source.cacheFileName || SHA1(uri) + '.pdf'; const cacheFile = ReactNativeBlobUtil.fs.dirs.CacheDir + '/' + filename; @@ -291,7 +292,11 @@ export default class Pdf extends Component { }); } else { if (this._mounted) { - const localPath = decodeURIComponent(uri.replace(/file:\/\//i, '')); + // Android grants scoped access to the exact content URI. Decoding + // it changes the permission key (for example, %3A becomes :). + const localPath = isContentUri + ? uri + : decodeURIComponent(uri.replace(/file:\/\//i, '')); if (this.props.transformFile) { try { const viewFile = await this._transformToViewFile(localPath);