Skip to content

fix: decode file:// URIs consistently before filesystem calls - #96397

Merged
mountiny merged 1 commit into
Expensify:mainfrom
callstack-internal:durable-receipts-file-uri-to-path
Jul 17, 2026
Merged

mountiny merged 1 commit into
Expensify:mainfrom
callstack-internal:durable-receipts-file-uri-to-path

Conversation

@adhorodyski

@adhorodyski adhorodyski commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Follow-up to #95852, which fixed one consumer (checkFileExists).

A file shared into the app arrives as a percent-encoded file:// URI: a space becomes %20 and a # becomes %23. Several consumers turned that URI into a filesystem path by only stripping the file:// prefix, without decoding. Walk through a file named Receipt #42.pdf: it arrives as .../Receipt%20%2342.pdf, the consumer strips the prefix and hands the still-encoded string to the filesystem, and the lookup fails because no file with that literal name exists on disk.

Two changes close this class of bugs:

  1. A new fileURIToPath helper turns a file:// URI into the decoded path, and falls back to the raw path when the string is not valid percent-encoding. It replaces the one-off conversions in getFileSize (the confirmed break: ShareRootPage feeds it the encoded share URI), verifyFileFormat, cropOrRotateImage, AttachmentPicker, FilePicker, ImportOnyxState, the decode step of checkFileExists, and the Android local-file download branch, which used decodeURI and left %23 encoded. Only file:// URIs are decoded. content:// URIs and remote URLs pass through untouched, so Android picker files and downloads behave exactly as before.
  2. moveReceiptToDurableStorage now sanitizes the on-disk filename with the existing cleanFileName helper, so the file:// URIs it produces never contain #, %, or a space. Without this, a file literally named Receipt %2342.pdf and an encoded Receipt #42.pdf are the same string, and no decode can tell them apart. The filename users see is not affected: it travels separately on the file object's name field (verified across receipt display, Onyx receipt.filename, and the upload payload).

Deliberately unchanged: checkFileExists keeps its stat-decoded-then-stat-raw fallback, because receipts queued offline before this change can still point at files with unsanitized names. The upload consumers (readFileAsync and the FormData uri) also stay on the encoded URI, which is the form fetch needs.

Fixed Issues

$ #95673
PROPOSAL:

Tests

  1. On an iPhone, share a file whose name contains # and a space into Expensify (open an email in Gmail → Print → Share → Expensify, e.g. Receipt #42.pdf) and submit the expense. Verify the expense is created with the receipt attached, not $0.
  2. Pick a receipt with a # in the filename via the in-app attachment picker and submit. Verify the receipt uploads and displays.
  3. Verify unit tests pass: npx jest tests/unit/fileURIToPathTest.ts tests/unit/getFileSizeTest.ts tests/unit/libs/receiptDurableStorageTest.ts tests/unit/verifyFileFormatTest.ts tests/unit/checkFileExistsTest.ts (34 tests).
  • Verify that no errors appear in the JS console

Offline tests

  1. Turn off the network. Share a file whose name contains # into Expensify and submit the expense. Turn the network back on. Verify the receipt uploads once the queue drains and the expense shows the receipt instead of $0.

QA Steps

Same as Tests steps 1-2 above.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Logic-only fix, covered by unit tests.

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@adhorodyski
adhorodyski force-pushed the durable-receipts-file-uri-to-path branch from 8f5e847 to 945778b Compare July 17, 2026 14:15
@codecov

codecov Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/fileDownload/FileUtils.ts 37.43% <100.00%> (+5.31%) ⬆️
src/libs/fileDownload/checkFileExists/index.ts 100.00% <100.00%> (ø)
src/libs/fileURIToPath.ts 100.00% <100.00%> (ø)
...c/libs/moveReceiptToDurableStorage/index.native.ts 100.00% <100.00%> (+29.41%) ⬆️
src/pages/Share/getFileSize/index.native.ts 100.00% <100.00%> (+66.66%) ⬆️
src/components/AttachmentPicker/index.native.tsx 19.32% <0.00%> (ø)
src/components/FilePicker/index.native.tsx 0.00% <0.00%> (ø)
src/components/ImportOnyxState/index.native.tsx 0.00% <0.00%> (ø)
src/libs/cropOrRotateImage/index.native.ts 2.63% <0.00%> (ø)
src/libs/fileDownload/index.android.ts 0.00% <0.00%> (ø)
... and 161 files with indirect coverage changes

@adhorodyski
adhorodyski force-pushed the durable-receipts-file-uri-to-path branch from 945778b to 78dbfdb Compare July 17, 2026 14:23
@adhorodyski
adhorodyski marked this pull request as ready for review July 17, 2026 14:26
@adhorodyski
adhorodyski requested review from a team as code owners July 17, 2026 14:26
@melvin-bot
melvin-bot Bot requested review from ZhenjaHorbach and joekaufmanexpensify and removed request for a team and joekaufmanexpensify July 17, 2026 14:26
@melvin-bot

melvin-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

@ZhenjaHorbach Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team July 17, 2026 14:26
@adhorodyski

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 78dbfdb68a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses receipt/file handling failures caused by percent-encoded file:// URIs (e.g., spaces as %20, # as %23) being passed into filesystem APIs without decoding. It centralizes decoding/normalization behind a single helper and ensures newly persisted receipt filenames are unambiguous on disk.

Changes:

  • Introduces a shared fileURIToPath helper to convert file:// URIs into decoded POSIX paths (with safe fallback on malformed percent-encoding).
  • Replaces ad-hoc file:// stripping / partial decoding across multiple filesystem call sites with fileURIToPath.
  • Sanitizes the on-disk filename produced by moveReceiptToDurableStorage via cleanFileName to avoid ambiguous % / # cases and improve durability.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/unit/verifyFileFormatTest.ts Adds coverage to ensure verifyFileFormat reads from decoded POSIX paths for encoded file:// URIs.
tests/unit/libs/receiptDurableStorageTest.ts Expands tests for decoding source URIs and sanitizing destination filenames in durable receipt storage.
tests/unit/getFileSizeTest.ts Adds tests verifying getFileSize stats decoded paths for encoded share URIs.
tests/unit/fileURIToPathTest.ts Adds unit tests for fileURIToPath decoding behavior and non-file:// pass-through.
src/pages/Share/getFileSize/index.native.ts Uses fileURIToPath before calling RNFS.stat to handle encoded share URIs.
src/libs/moveReceiptToDurableStorage/index.native.ts Decodes source file:// URIs before moving; sanitizes on-disk destination filename via cleanFileName.
src/libs/fileURIToPath.ts New helper to convert file:// URIs into decoded filesystem paths with fallback on invalid encoding.
src/libs/fileDownload/index.android.ts Uses fileURIToPath for local file:// downloads so Android media copy/unlink receives a bare POSIX path.
src/libs/fileDownload/FileUtils.ts Updates verifyFileFormat to use fileURIToPath instead of only stripping file://.
src/libs/fileDownload/checkFileExists/index.ts Uses fileURIToPath for the decoded candidate path while keeping the decoded-then-raw fallback behavior.
src/libs/cropOrRotateImage/index.native.ts Uses fileURIToPath for RNFetchBlob.fs.stat calls on manipulated image URIs and fallback path usage.
src/components/ImportOnyxState/index.native.tsx Uses fileURIToPath to convert file:// URIs to filesystem paths before blob-util operations.
src/components/FilePicker/index.native.tsx Uses fileURIToPath before RNFetchBlob.fs.stat to support encoded file:// URIs.
src/components/AttachmentPicker/index.native.tsx Uses fileURIToPath before RNFetchBlob.fs.stat when size is missing, supporting encoded file:// URIs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ZhenjaHorbach

ZhenjaHorbach commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
2026-07-17.17.10.56.mov
Android: mWeb Chrome
2026-07-17.17.10.56.mov
iOS: HybridApp
2026-07-17.16.59.13.mov
iOS: mWeb Safari
2026-07-17.17.02.51.mov
MacOS: Chrome / Safari
2026-07-17.16.56.55.mov
2026-07-17.17.12.50.mov

@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

Changes look and work good!

@melvin-bot
melvin-bot Bot requested a review from mountiny July 17, 2026 15:14
@mountiny
mountiny merged commit 2a50714 into Expensify:main Jul 17, 2026
37 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@adhorodyski
adhorodyski deleted the durable-receipts-file-uri-to-path branch July 20, 2026 08:37
@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.41-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 I reviewed the changes in this PR against the help site articles under App/docs/articles.

No help site changes are required.

This is an internal logic-only bug fix: it adds a fileURIToPath helper so that percent-encoded file:// URIs are decoded consistently before filesystem calls, and sanitizes the on-disk receipt filename via cleanFileName. The net effect is that receipts whose filenames contain #, a space, or % (e.g. Receipt #42.pdf) now upload and attach correctly instead of failing.

There is no user-facing surface change here — no new or renamed feature, tab, setting, button, or workflow — and the fix is transparent to users. The help site never documented any restriction on special characters in receipt filenames (I searched the articles for filename-related guidance and the only matches concern unrelated import/export/API topics), so there is nothing to add, correct, or remove.

Since no documentation update is needed, I did not create a draft PR.

@adhorodyski, if you believe a specific article should mention this behavior, let me know which one and I'll draft the update.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/yuwenmemon in version: 9.4.41-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants