Repository navigation
Conversation
`getFilename()` returned the raw `URL` pathname segment, so filenames with non-ASCII characters or spaces came back percent-encoded. For example, the Media tab in the block inserter showed `%E7%94%9F%E6%88%90…` instead of `生成波の音1.mp3` for audio files. Decode the filename with `safeDecodeURIComponent()` after splitting the path, so an encoded slash (`%2F`) stays part of the filename. A filename that can't be decoded is returned unchanged. Add `getFilename` unit tests for encoded, unencoded and undecodable names, and a `FilePreview` test for the inserter's media preview.
🤖 PR meta 🤖👋 Welcome👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @umeshnevase! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. 🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
|
Thanks @umeshnevase! Closing this in favour of #86384, which was opened first with a similar fix. Your review and tests would be very welcome there. 🙏 |
|
@im3dabasia I think we should reopen this PR and close #86384 instead. The root cause is that Besides the audio preview reported in the original issue,
|
|
Thanks Aki, agreed. Fixing it in |
im3dabasia
left a comment
There was a problem hiding this comment.
Overall this looks good to me and tests well! @t-hamano, could you give it a second look? Thanks to everyone who contributed to this issue. 🙏
| @@ -2,6 +2,10 @@ | |||
|
|
|||
| ## Unreleased | |||
|
|
|||
| ### Bug Fixes | |||
|
|
|||
| - `getFilename`: Decode percent-encoded characters, so filenames with non-ASCII characters or spaces, such as `生成波の音1.mp3`, are returned as written instead of as `%E7%94%9F…`. | |||
There was a problem hiding this comment.
Can we change it to this? It's a shorter, crisper entry, and it adds the PR link so the CHANGELOG check passes.
- `getFilename`: Decode the filename so non-ASCII names read as written ([#86422](https://github.com/WordPress/gutenberg/pull/86422)).
t-hamano
left a comment
There was a problem hiding this comment.
LGTM!
| Location | Screenshot |
|---|---|
| Inserter: Media → Audio preview | ![]() |
| Media modal (experiment): Grid view | ![]() |
| Media modal (experiment): Table view, File name | ![]() |
| Media Editor (experiment): File name | ![]() |
| Block sidebar: Background image label | ![]() |
| Audio ×2 → Playlist transform: Track titles | ![]() |
@Mamaduka @peterwilsoncc, this PR fixes the issue in six places. Only the first one is newly exposed in 7.2, but I'd love to see this fix included in 7.2. The only substantive logic change is this one line. What do you think?
Same here, it'd be great to get this in for 7.2 as the media inserter has been newly redesigned and the filename is exposed in quite a prominent way for anyone inserting audio via the inserter. Thanks for the fix @umeshnevase! |
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
|
There was a conflict while trying to cherry-pick the commit to the wp/7.2 branch. Please resolve the conflict manually and create a PR to the wp/7.2 branch. PRs to wp/7.2 are similar to PRs to trunk, but you should base your PR on the wp/7.2 branch instead of trunk. |
* URL: Decode percent-encoded characters in getFilename `getFilename()` returned the raw `URL` pathname segment, so filenames with non-ASCII characters or spaces came back percent-encoded. For example, the Media tab in the block inserter showed `%E7%94%9F%E6%88%90…` instead of `生成波の音1.mp3` for audio files. Decode the filename with `safeDecodeURIComponent()` after splitting the path, so an encoded slash (`%2F`) stays part of the filename. A filename that can't be decoded is returned unchanged. Add `getFilename` unit tests for encoded, unencoded and undecodable names, and a `FilePreview` test for the inserter's media preview. * Update changelog entry --------- (cherry picked from commit 4ee84f3) Claude-Session: https://claude.ai/code/session_011g9URwkBYKiuQZEapk8PBC Co-authored-by: umeshnevase <umeshnevase@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: im3dabasia1 <im3dabasia1@git.wordpress.org> Co-authored-by: nendeb55 <nendeb55@git.wordpress.org>
|
Backported: #86477 |
This updates the pinned commit hash of the Gutenberg repository from `c035c1a649ef68f5c1646694cf440df1d7ae6e62` to `1b0dc90c700746b108e080263a4dc67707b750a1` (fixes cherry-picked to the `wp/7.2` branch). A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@c035c1a...1b0dc90 - [WP 7.2] Components, UI: Use focus-visible for disabled item focus rings (WordPress/gutenberg#86269) - Notes: Keep the canvas still when a new note is added (WordPress/gutenberg#86283) (#86293) - Post summary: Show placeholders for an empty excerpt and a missing author (WordPress/gutenberg#85842) (#86294) - Core fields: Restore the previous Publish and Status panel date behaviour (WordPress/gutenberg#86065) (#86295) - Interactivity API: Show the data-wp-html fallback on created elements under Trusted Types (WordPress/gutenberg#84924) (#86306) - [WP 7.2] UI: Add LoadingIndicator to item popups (WordPress/gutenberg#86303) - Interactivity Router: Fix nested router regions without data-wp-interactive disappearing on navigation (WordPress/gutenberg#86061) (#86308) - Interactivity API: Run watch() cleanups and attachTo render callbacks without a directive scope (WordPress/gutenberg#86058) (#86311) - DataForm: Fix clipped focus ring of field values in panel layout (WordPress/gutenberg#86361) (#86369) - Tests: Avoid passing an object when invoking static methods via reflection. (WordPress/gutenberg#86329) - [WP 7.2] DropdownMenu: Invert the selected item indicator while highlighted (WordPress/gutenberg#86379) - Fields: Lowercase the (no excerpt), (no author) and (no description) placeholders (WordPress/gutenberg#86391) (#86424) - Core fields: Decode non-Latin slugs in the slug field (WordPress/gutenberg#86359) - Interactivity API: Show the new page's server content in kept data-wp-html elements (WordPress/gutenberg#86416) - DataForm: Tighten value density in the panel layout (WordPress/gutenberg#86389) (#86426) - Post summary: Show "Immediately" and relative publish dates in the Date row (WordPress/gutenberg#86367) - [WP 7.2] Block Styles: Show the active style variation in forced colors mode (WordPress/gutenberg#86450) - Site Editor: Fix the frame snapping to the mobile width when resized with the mouse (WordPress/gutenberg#86423) - Image: measure the lightbox container, not the image's parent (WordPress/gutenberg#82312) (#85491) - URL: Decode percent-encoded characters in getFilename (WordPress/gutenberg#86422) (#86477) - Fix: Hide the author avatar when the site does not show avatars and frame a blank one. (WordPress/gutenberg#86395) - Date picker: Mark the posts of the month a typed or reset date moves to (WordPress/gutenberg#86298) (#86463) - Fix iOS 27 tap into a heading leaving the caret in a quote (WordPress/gutenberg#85809) - Hand focus back to the field on a press in every browser (WordPress/gutenberg#86549) - Prevent jobs from running within forks on `push`. (WordPress/gutenberg#85968) - i18n: Add translator context to the "Copy error" button label (WordPress/gutenberg#85967) - Bubble editor canvas events to the outer iframe (WordPress/gutenberg#85263) - UI: Use LoadingIndicator in remaining popup consumers (WordPress/gutenberg#86501) - Block Editor: Keep the revision canvas read-only in preview mode (WordPress/gutenberg#84578) - Core Data: Rank an exact title match first among tied link suggestions (WordPress/gutenberg#86327) - Tests: Render the router-html-server context case through state (WordPress/gutenberg#86511) - iOS tests: De-flake the selection handle test (WordPress/gutenberg#85461) Props mamaduka, wildworks. See #66340. git-svn-id: https://develop.svn.wordpress.org/trunk@65379 602fd350-edb4-49c9-b593-d223f7449a82
This updates the pinned commit hash of the Gutenberg repository from `c035c1a649ef68f5c1646694cf440df1d7ae6e62` to `1b0dc90c700746b108e080263a4dc67707b750a1` (fixes cherry-picked to the `wp/7.2` branch). A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@c035c1a...1b0dc90 - [WP 7.2] Components, UI: Use focus-visible for disabled item focus rings (WordPress/gutenberg#86269) - Notes: Keep the canvas still when a new note is added (WordPress/gutenberg#86283) (#86293) - Post summary: Show placeholders for an empty excerpt and a missing author (WordPress/gutenberg#85842) (#86294) - Core fields: Restore the previous Publish and Status panel date behaviour (WordPress/gutenberg#86065) (#86295) - Interactivity API: Show the data-wp-html fallback on created elements under Trusted Types (WordPress/gutenberg#84924) (#86306) - [WP 7.2] UI: Add LoadingIndicator to item popups (WordPress/gutenberg#86303) - Interactivity Router: Fix nested router regions without data-wp-interactive disappearing on navigation (WordPress/gutenberg#86061) (#86308) - Interactivity API: Run watch() cleanups and attachTo render callbacks without a directive scope (WordPress/gutenberg#86058) (#86311) - DataForm: Fix clipped focus ring of field values in panel layout (WordPress/gutenberg#86361) (#86369) - Tests: Avoid passing an object when invoking static methods via reflection. (WordPress/gutenberg#86329) - [WP 7.2] DropdownMenu: Invert the selected item indicator while highlighted (WordPress/gutenberg#86379) - Fields: Lowercase the (no excerpt), (no author) and (no description) placeholders (WordPress/gutenberg#86391) (#86424) - Core fields: Decode non-Latin slugs in the slug field (WordPress/gutenberg#86359) - Interactivity API: Show the new page's server content in kept data-wp-html elements (WordPress/gutenberg#86416) - DataForm: Tighten value density in the panel layout (WordPress/gutenberg#86389) (#86426) - Post summary: Show "Immediately" and relative publish dates in the Date row (WordPress/gutenberg#86367) - [WP 7.2] Block Styles: Show the active style variation in forced colors mode (WordPress/gutenberg#86450) - Site Editor: Fix the frame snapping to the mobile width when resized with the mouse (WordPress/gutenberg#86423) - Image: measure the lightbox container, not the image's parent (WordPress/gutenberg#82312) (#85491) - URL: Decode percent-encoded characters in getFilename (WordPress/gutenberg#86422) (#86477) - Fix: Hide the author avatar when the site does not show avatars and frame a blank one. (WordPress/gutenberg#86395) - Date picker: Mark the posts of the month a typed or reset date moves to (WordPress/gutenberg#86298) (#86463) - Fix iOS 27 tap into a heading leaving the caret in a quote (WordPress/gutenberg#85809) - Hand focus back to the field on a press in every browser (WordPress/gutenberg#86549) - Prevent jobs from running within forks on `push`. (WordPress/gutenberg#85968) - i18n: Add translator context to the "Copy error" button label (WordPress/gutenberg#85967) - Bubble editor canvas events to the outer iframe (WordPress/gutenberg#85263) - UI: Use LoadingIndicator in remaining popup consumers (WordPress/gutenberg#86501) - Block Editor: Keep the revision canvas read-only in preview mode (WordPress/gutenberg#84578) - Core Data: Rank an exact title match first among tied link suggestions (WordPress/gutenberg#86327) - Tests: Render the router-html-server context case through state (WordPress/gutenberg#86511) - iOS tests: De-flake the selection handle test (WordPress/gutenberg#85461) Props mamaduka, wildworks. See #66340. Built from https://develop.svn.wordpress.org/trunk@65379 git-svn-id: http://core.svn.wordpress.org/trunk@64518 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This updates the pinned commit hash of the Gutenberg repository from `c035c1a649ef68f5c1646694cf440df1d7ae6e62` to `1b0dc90c700746b108e080263a4dc67707b750a1` (fixes cherry-picked to the `wp/7.2` branch). A full list of changes included in this commit can be found on GitHub: WordPress/gutenberg@c035c1a...1b0dc90 - [WP 7.2] Components, UI: Use focus-visible for disabled item focus rings (WordPress/gutenberg#86269) - Notes: Keep the canvas still when a new note is added (WordPress/gutenberg#86283) (#86293) - Post summary: Show placeholders for an empty excerpt and a missing author (WordPress/gutenberg#85842) (#86294) - Core fields: Restore the previous Publish and Status panel date behaviour (WordPress/gutenberg#86065) (#86295) - Interactivity API: Show the data-wp-html fallback on created elements under Trusted Types (WordPress/gutenberg#84924) (#86306) - [WP 7.2] UI: Add LoadingIndicator to item popups (WordPress/gutenberg#86303) - Interactivity Router: Fix nested router regions without data-wp-interactive disappearing on navigation (WordPress/gutenberg#86061) (#86308) - Interactivity API: Run watch() cleanups and attachTo render callbacks without a directive scope (WordPress/gutenberg#86058) (#86311) - DataForm: Fix clipped focus ring of field values in panel layout (WordPress/gutenberg#86361) (#86369) - Tests: Avoid passing an object when invoking static methods via reflection. (WordPress/gutenberg#86329) - [WP 7.2] DropdownMenu: Invert the selected item indicator while highlighted (WordPress/gutenberg#86379) - Fields: Lowercase the (no excerpt), (no author) and (no description) placeholders (WordPress/gutenberg#86391) (#86424) - Core fields: Decode non-Latin slugs in the slug field (WordPress/gutenberg#86359) - Interactivity API: Show the new page's server content in kept data-wp-html elements (WordPress/gutenberg#86416) - DataForm: Tighten value density in the panel layout (WordPress/gutenberg#86389) (#86426) - Post summary: Show "Immediately" and relative publish dates in the Date row (WordPress/gutenberg#86367) - [WP 7.2] Block Styles: Show the active style variation in forced colors mode (WordPress/gutenberg#86450) - Site Editor: Fix the frame snapping to the mobile width when resized with the mouse (WordPress/gutenberg#86423) - Image: measure the lightbox container, not the image's parent (WordPress/gutenberg#82312) (#85491) - URL: Decode percent-encoded characters in getFilename (WordPress/gutenberg#86422) (#86477) - Fix: Hide the author avatar when the site does not show avatars and frame a blank one. (WordPress/gutenberg#86395) - Date picker: Mark the posts of the month a typed or reset date moves to (WordPress/gutenberg#86298) (#86463) - Fix iOS 27 tap into a heading leaving the caret in a quote (WordPress/gutenberg#85809) - Hand focus back to the field on a press in every browser (WordPress/gutenberg#86549) - Prevent jobs from running within forks on `push`. (WordPress/gutenberg#85968) - i18n: Add translator context to the "Copy error" button label (WordPress/gutenberg#85967) - Bubble editor canvas events to the outer iframe (WordPress/gutenberg#85263) - UI: Use LoadingIndicator in remaining popup consumers (WordPress/gutenberg#86501) - Block Editor: Keep the revision canvas read-only in preview mode (WordPress/gutenberg#84578) - Core Data: Rank an exact title match first among tied link suggestions (WordPress/gutenberg#86327) - Tests: Render the router-html-server context case through state (WordPress/gutenberg#86511) - iOS tests: De-flake the selection handle test (WordPress/gutenberg#85461) Props mamaduka, wildworks. See #66340. git-svn-id: https://develop.svn.wordpress.org/trunk@65379 602fd350-edb4-49c9-b593-d223f7449a82












What?
Closes #86380
Why?
getFilename()returned the rawURLpathname segment, so filenames with non-ASCII characters or spaces came back percent-encoded. For example, the Media tab in the block inserter showed%E7%94%9F%E6%88%90…instead of生成波の音1.mp3for audio files.Decode the filename with
safeDecodeURIComponent()after splitting the path, so an encoded slash (%2F) stays part of the filename. A filename that can't be decoded is returned unchanged.Add
getFilenameunit tests for encoded, unencoded and undecodable names, and aFilePreviewtest for the inserter's media preview.How?
getFilename()in@wordpress/urltook the last segment ofnew URL( url ).pathname. The browser's URL parser percent-encodes non-ASCII characters in the path, even when the stored URL is plain text. So a file such as生成波の音1.mp3came back as%E7%94%9F%E6%88%90…. The Media tab's audio preview builds its label from that function, so it showed the encoded name, which is also truncated by the tile width. The Media Library doesn't usegetFilename(), so it was unaffected.The fix is in
getFilename()itself, so every caller gets the readable name:safeDecodeURIComponent()helper. The decoding happens after the path is split, so an encoded slash (%2F) stays part of the filename instead of acting as a separator.%E9%9F, is returned unchanged instead of throwing.getFilename()is also used for labels in the image, cover and media-text blocks, the file and playlist transforms, and the media filename fields. Those only display the name or check its extension, so they now show the readable name too.Files changed:
packages/url/src/get-filename.ts: the fix.packages/url/src/test/index.jsdom.test.ts: unit tests for encoded, unencoded, spaced,%2F, literal%and undecodable names.packages/block-editor/src/components/inserter/media-tab/test/file-preview.jsdom.test.tsx: new component test for the inserter's audio preview.packages/url/README.mdandpackages/url/CHANGELOG.md: docs and a Bug Fixes entry.Testing Instructions
生成波の音1.mp3, through Media → Add New.%E7%94%9F%E6%88%90%E6%B3%A2….生成波の音1.mp3.my recording.mp3, and one with a plain ASCII name. Both should show the name as written.To run the tests:
Testing Instructions for Keyboard
This PR changes the text of a label and not how anything is operated. To check it with the keyboard:
生成波の音1.mp3, not the percent-encoded form.Screenshots or screencast
Use of AI Tools
I used Claude Code to help investigate the cause, write the fix and the tests, and draft this description. I reviewed the changes and ran the tests and lint myself.