Repository navigation
Abilities: Accept non-ASCII URLs in the uri schema format - #86844
Conversation
🤖 PR meta 🤖🎉 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 📦 Bundle sizeSize Change: +19 B (0%) Total Size: 8.69 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. List in
|
gziolo
left a comment
There was a problem hiding this comment.
Looks good to me! I was curious why this was needed and whether the differences came from draft-04 being quite old, so I explored it further with Codex.
Why this is needed
The useful distinction is uri versus iri. JSON Schema's uri format follows RFC 3986 and requires ASCII. That is still true in JSON Schema 2020-12, which provides a separate iri format for internationalized identifiers. So moving to a newer draft alone would not resolve this.
WordPress can produce URLs with Unicode characters in permalink prefixes, domain names, and filenames. It declares these values as uri, but its server-side schema validation does not enforce that format. The existing client check can therefore reject legitimate output after the ability has completed successfully on the server.
Using the platform URL parser makes sense here. It brings the client closer to what WordPress actually produces and accepts, and the broader parsing tolerance seems reasonable for that purpose. Thanks for fixing this!
bc3af32 to
76219b1
Compare
The `uri` check of ajv-formats follows RFC 3986 and is ASCII only, so the client rejected URLs that WordPress serves: a permalink under a permalink structure or a post type slug with non-ASCII characters, the URL of a file with a non-ASCII name, or any URL of a site on an internationalized domain. Core abilities declare `format: uri` on the links they return and the server does not check that format, so a call the server completed failed on the client with `ability_invalid_output`. The format now accepts what the platform URL parser accepts as an absolute URL. An empty string and a relative URL are still rejected.
76219b1 to
10e4ea0
Compare
|
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. |
What?
Follow up to #79555.
The client-side validator of
@wordpress/abilitiesnow checks theurischema format with the URL parser of the platform (new URL()), in place of theuricheck ofajv-formats.URLs with non-ASCII characters, which WordPress serves, are now valid. Values that are not absolute URLs, such as an empty string or a relative URL, are still rejected.
Why?
executeAbility()validates the result of an ability against its output schema and throwsability_invalid_outputwhen it does not match. One value that fails is enough: the caller gets none of the result.The
uricheck ofajv-formatsis a regular expression that follows RFC 3986 and accepts ASCII only. WordPress builds URLs with other characters, and they open in every browser:https://example.com/блог/hello-world/https://example.com/produkte-größe/stuhl/https://例え.jp/hello-world/https://example.com/wp-content/uploads/2026/11/写真.jpgPost slugs are not in this list: WordPress percent-encodes them, so
https://example.com/%e6%96%87%e7%ab%a0/was already valid.Nothing on the server rejects these URLs.
rest_validate_value_from_schema()has no case foruri, so the server validates the output and completes the call. The client then throws on a result that is correct, and the site owner cannot fix it, because the URLs are valid.How core abilities use the
uriformatCore abilities declare
format: urion a value so that a client (the editor, an agent, an MCP client) can tell from the schema that the string is an absolute URL to open or fetch, and not a slug or a path.Already in WordPress trunk:
core/users-query:link, which is one of the default fields, and each value ofavatar_urls.core/settings-get:url, from the schema the setting is registered with.Proposed:
core/content-query:link, in Abilities API: Declare theuriformat for thelinkoutput ofcore/content-querywordpress-develop#15987.linkof a post, a term and an attachment, and for thesource_urlof a file and of each image size.urlincore/settings-update, and the URL of the file to add incore/media-upload. The client validates the input before it sends the request, so the ASCII-only check would also refuse an upload fromhttps://example.com/写真.jpg.With the ASCII-only check, on a site with any of the URL forms above,
core/users-queryfails in the client today, and each ability that returns a link would fail as it lands.How?
uriis no longer one of the formats taken fromajv-formats. It is registered withajv.addFormat( 'uri', isAbsoluteUrl ), whereisAbsoluteUrl()returns whethernew URL( value )parses the value. This is whatisURL()of@wordpress/urldoes; the few lines are inlined so that the package does not gain a dependency.The error message does not change, for example
output[items][1][link] is not a valid URI.https://example.com/2026/11/hello-world/https://example.com/?p=123https://example.com/%e6%96%87%e7%ab%a0/https://xn--r8jz45g.jp/hello-world/https://example.com/блог/hello-world/https://example.com/produkte-größe/stuhl/https://例え.jp/hello-world/https://example.com/wp-content/uploads/2026/11/写真.jpg/2026/11/hello-world///example.com/hello-world/https://exa mple.com/https://Two things to know about the new check:
format: urion a value that can be an empty string.core/users-queryleaves the format out of the user'surlfor that reason.Testing Instructions
npm run test:unit -- packages/abilities/src/tests/validation.test.ts. All tests pass.AI-relevant format validationgroup:should accept %s as a URI: the forms a WordPress URL takes in the output of an ability, eleven cases.should reject %s as a URI: an empty string, a root-relative URL, a protocol-relative URL, a URL without a host and a host with a space.should validate the links in a result shaped like the output of a core ability: a page of items, each with alink, ascore/content-queryreturns it, with the error for a relative link.packages/abilities/src/validation.tsand run the tests again: six of the new tests fail.Optionally, in a site that runs WordPress trunk:
/блог/%postname%/.core/users-querywithexecuteAbility()of@wordpress/abilities.ability_invalid_outputerror that names thelinkof the first user. With this PR it returns the users.Testing Instructions for Keyboard
Not applicable, there is no change to the user interface.
Screenshots or screencast
Not applicable.
Use of AI Tools
An AI coding assistant drafted the code change, the tests and this description.