fix: decode the local file path before handing it to the media upload API - #26005
Open
jkmassel wants to merge 1 commit into
Open
fix: decode the local file path before handing it to the media upload API#26005jkmassel wants to merge 1 commit into
jkmassel wants to merge 1 commit into
Conversation
… API
`URL.path()` percent-encodes by default, unlike the legacy `url.path`
property. `MediaCreateParams` passed the encoded form as `filePath`, so any
media file whose name needs encoding could not be found on disk:
WpApiError.MediaFileNotFound(filePath:
".../screenrecording_08-27-2024%2012-12-08_1.mp4")
while the file on disk was `screenrecording_08-27-2024 12-12-08_1.mp4`.
A space is enough to trigger it, which makes this reachable with ordinary
content: screen recordings and files imported from macOS routinely have
spaces in their names.
Collaborator
Generated by 🚫 Danger |
jkmassel
marked this pull request as ready for review
September 8, 2026 21:33
Contributor
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 34428 | |
| Version | PR #26005 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | b1f5001 | |
| Installation URL | 4c59spefarpb0 |
Contributor
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 34428 | |
| Version | PR #26005 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | b1f5001 | |
| Installation URL | 0hsv9cji63420 |
This was referenced Sep 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fixes a bug where any media file whose name needs percent-encoding — a space is enough — fails to upload through the WordPress core REST API.
Summary
URL.path()percent-encodes by default, unlike the legacyurl.pathproperty, which returns a decoded path.MediaCreateParamspassed the encoded form asfilePath, sowordpress-rslooked for a file that doesn't exist on disk.Root Cause
WordPress/Classes/Services/MediaServiceRemoteCoreREST.swift:
MediaCreateParams.init?(media:)builtfilePathwithlocalURL.path().The two APIs differ in a way the names don't advertise:
Observed on device, uploading a screen recording:
The file on disk was
screenrecording_08-27-2024 12-12-08_1.mp4. Confirmed by listing the app'sDocuments/Mediadirectory on the device — the name there has a literal space.The export itself succeeds, so the failure lands late: the media object is created,
media_service_upload_startedfires, and the upload then fails withMediaFileNotFound.Fix
WordPress/Classes/Services/MediaServiceRemoteCoreREST.swift: pass
localURL.path(percentEncoded: false).Test plan
MediaCreateParamsFilePathTests— a filename with a space, one with a%, and a control that needs no encoding.screen%20recording%201.mp4), and that the control passes either way.MediaFileNotFoundbefore the change and uploaded successfully after it.Notes
MediaCreateParams's extension is no longerprivate, so the test can reach it. The comment on it says why.Four other
.path()call sites share this shape and are not changed here —SupportDataProvider(x2),AsyncImageKit/ImageDownloader, andWordPressCore/DiskCache. They looked safe because the paths are app-generated, but that was not verified and is worth a separate sweep.