Skip to content

Abilities: Accept non-ASCII URLs in the uri schema format - #86844

Merged
jorgefilipecosta merged 2 commits into
trunkfrom
fix/abilities-uri-format-non-ascii-urls
Nov 20, 2026
Merged

jorgefilipecosta merged 2 commits into
trunkfrom
fix/abilities-uri-format-non-ascii-urls

Conversation

@jorgefilipecosta

Copy link
Copy Markdown
Member

What?

Follow up to #79555.

The client-side validator of @wordpress/abilities now checks the uri schema format with the URL parser of the platform (new URL()), in place of the uri check of ajv-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 throws ability_invalid_output when it does not match. One value that fails is enough: the caller gets none of the result.

The uri check of ajv-formats is a regular expression that follows RFC 3986 and accepts ASCII only. WordPress builds URLs with other characters, and they open in every browser:

Where the characters come from Example
The permalink structure, which is saved as typed https://example.com/блог/hello-world/
The rewrite slug of a post type or a taxonomy https://example.com/produkte-größe/stuhl/
A site address on an internationalized domain name https://例え.jp/hello-world/
The name of an uploaded file https://example.com/wp-content/uploads/2026/11/写真.jpg

Post 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 for uri, 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 uri format

Core abilities declare format: uri on 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 of avatar_urls.
  • core/settings-get: url, from the schema the setting is registered with.

Proposed:

With the ASCII-only check, on a site with any of the URL forms above, core/users-query fails in the client today, and each ability that returns a link would fail as it lands.

How?

uri is no longer one of the formats taken from ajv-formats. It is registered with ajv.addFormat( 'uri', isAbsoluteUrl ), where isAbsoluteUrl() returns whether new URL( value ) parses the value. This is what isURL() of @wordpress/url does; 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.

Value Before After
https://example.com/2026/11/hello-world/ valid valid
https://example.com/?p=123 valid valid
https://example.com/%e6%96%87%e7%ab%a0/ valid valid
https://xn--r8jz45g.jp/hello-world/ valid valid
https://example.com/блог/hello-world/ invalid valid
https://example.com/produkte-größe/stuhl/ invalid valid
https://例え.jp/hello-world/ invalid valid
https://example.com/wp-content/uploads/2026/11/写真.jpg invalid valid
An empty string invalid invalid
/2026/11/hello-world/ invalid invalid
//example.com/hello-world/ invalid invalid
https://exa mple.com/ invalid invalid
https:// valid invalid

Two things to know about the new check:

  • It is more lenient than RFC 3986 in other ways too. The URL parser accepts a space in the path and white space around the value, and encodes or trims them. As before, any scheme is accepted.
  • The client is still stricter than the server, which does not check the format at all. A schema should not declare format: uri on a value that can be an empty string. core/users-query leaves the format out of the user's url for that reason.

Testing Instructions

  1. Run npm run test:unit -- packages/abilities/src/tests/validation.test.ts. All tests pass.
  2. The new tests are in the AI-relevant format validation group:
    • 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 a link, as core/content-query returns it, with the error for a relative link.
  3. To see the bug, revert the change to packages/abilities/src/validation.ts and run the tests again: six of the new tests fail.

Optionally, in a site that runs WordPress trunk:

  1. Set a permalink structure with non-ASCII characters in Settings > Permalinks, for example /блог/%postname%/.
  2. Execute core/users-query with executeAbility() of @wordpress/abilities.
  3. On trunk the call throws an ability_invalid_output error that names the link of 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.

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended [Package] Abilities /packages/abilities labels Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +19 B (0%)

Total Size: 8.69 MB

📦 View Changed
Filename Size Change
build/modules/abilities/index.min.js 41.3 kB +19 B (+0.05%)

10e4ea0 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 24d83d7 trunk % Change
timeToFirstByte 44.6 ms +7.4% -5.38% 45.6 ms +10.75% -4.39% -2.19%
largestContentfulPaint 70 ms +5.71% -5.71% 76 ms +10.53% -10.53% -7.89%
lcpMinusTtfb 23.7 ms +7.38% -4.22% 32.4 ms +2.93% -28.7% -26.85%
wpBeforeTemplate 23.08 ms +14.82% -4.29% 23.23 ms +16.75% -2.41% -0.65%
wpTemplate 17.74 ms +2.48% -7.05% 18.4 ms +5.76% -4.18% -3.59%
wpTotal 41.09 ms +7.96% -5.79% 41.81 ms +12.27% -3.85% -1.72%
wpMemoryUsage 7.75 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 24d83d7 trunk % Change
timeToFirstByte 35 ms +8.71% -2.57% 37.05 ms +7.69% -2.56% -5.53%
largestContentfulPaint 64 ms +6.25% -0% 68 ms +2.94% -5.88% -5.88%
lcpMinusTtfb 29 ms +2.24% -6.38% 28.75 ms +6.43% -5.57% 0.87%
wpBeforeTemplate 19.15 ms +2.77% -1.04% 19.88 ms +10.76% -1.31% -3.67%
wpTemplate 12.95 ms +6.72% -4.63% 14.19 ms +8.6% -4.93% -8.74%
wpTotal 32.37 ms +6.24% -2.69% 34.23 ms +8.15% -3.04% -5.43%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 24d83d7 trunk % Change
mediaProcessingJpeg 328.66 ms +1.15% -0.08% 332.3 ms +0.31% -1.23% -1.1%
mediaProcessingAvif 4864.44 ms +0.93% -0.11% 4867.82 ms +0.29% -0.12% -0.07%
mediaProcessingJpegToAvif 3418.17 ms +0.14% -0.44% 3405.15 ms +0.11% -0.19% 0.38%

media-upload

Metric 24d83d7 trunk % Change
jpegUploadProcessing 1490.01 ms +1.11% -1.21% 1465.22 ms +1.31% -0.58% 1.69%
pngUploadProcessing 249.46 ms +3.71% -7.29% 245.92 ms +1.26% -2.9% 1.44%
largeJpegUploadProcessing 1448.16 ms +0.48% -0.55% 1448.93 ms +0.28% -0.23% -0.05%
multipleImageUploadProcessing 1576.12 ms +8.53% -2.58% 1566.43 ms +1% -1.07% 0.62%

post-editor

Metric 24d83d7 trunk % Change
serverResponse 276.85 ms +4.43% -8.43% 267.97 ms +6.05% -3.45% 3.31%
firstPaint 300.37 ms +10.25% -7.81% 288.17 ms +8.46% -9.63% 4.23%
domContentLoaded 570.46 ms +2.57% -1.96% 546.19 ms +3.47% -1.84% 4.44%
loaded 571.37 ms +2.57% -1.91% 547.02 ms +3.48% -1.83% 4.45%
firstContentfulPaint 323.57 ms +4.18% -1.33% 314.55 ms +3.33% -4.83% 2.87%
firstBlock 1530.17 ms +2.45% -1.54% 1478.29 ms +1.4% -3.29% 3.51%
type 14.07 ms +10.16% -8.17% 13.77 ms +3.56% -10.38% 2.18%
typeWithoutInspector 13.64 ms +5.13% -7.55% 14.39 ms +3.61% -8.48% -5.21%
typeWithTopToolbar 16.15 ms +12.07% -6.75% 16.35 ms +4.1% -4.59% -1.22%
typeContainer 5.94 ms +9.93% -11.28% 6.76 ms +12.87% -11.09% -12.13%
focus 76.61 ms +5% -3.56% 78.01 ms +9.38% -4.04% -1.79%
firstFocus 177.03 ms +0% -0% 172.47 ms +0% -0% 2.64%
selectAll 235.51 ms +2.29% -3.87% 254.82 ms +9.08% -0.18% -7.58%
undo 18.54 ms +10.03% -5.34% 20.78 ms +8.71% -5.15% -10.78%
listViewOpen 50.21 ms +11.27% -15.95% 44.68 ms +4.03% -8.35% 12.38%
inserterOpen 27.67 ms +5.1% -6.61% 26.45 ms +4.69% -5.1% 4.61%
inserterHover 8.81 ms +5.22% -2.5% 8.84 ms +8.6% -6.67% -0.34%
inserterSearch 6.39 ms +9.7% -4.54% 6.41 ms +3.59% -4.68% -0.31%
loadPatterns 433.63 ms +4.49% -1.29% 438.28 ms +11.54% -4.28% -1.06%
wpTotal 269.89 ms +4.17% -8.79% 261.03 ms +5.76% -3.37% 3.39%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 24d83d7 trunk % Change
serverResponse 389.03 ms +2.82% -7.32% 385.61 ms +2.99% -7.75% 0.89%
firstPaint 388.98 ms +14.54% -9.35% 448.54 ms +1.33% -9.95% -13.28%
domContentLoaded 789.94 ms +3.72% -0.68% 784.78 ms +1.21% -0.45% 0.66%
loaded 791.03 ms +3.7% -0.67% 785.73 ms +1.19% -0.43% 0.67%
firstContentfulPaint 451.71 ms +6.79% -2.27% 451.99 ms +1.02% -1.5% -0.06%
firstBlock 2310.93 ms +2.8% -1.12% 2296.04 ms +2.87% -0.28% 0.65%
type 16.99 ms +3.65% -10.3% 16.69 ms +3.89% -10.31% 1.8%
navigate 103.82 ms +8.32% -0.81% 108.72 ms +2.26% -5.95% -4.51%
loadPatterns 1326.79 ms +2.75% -8.23% 1206.8 ms +5.72% -13.11% 9.94%
loadPages 925.15 ms +1.48% -2.25% 915.88 ms +2.52% -0.92% 1.01%
wpTotal 379.75 ms +2.81% -7.51% 376.17 ms +3.09% -8% 0.95%
wpMemoryUsage 12.83 MB +0% -0% 12.80 MB +0% -0% 0.25%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

10e4ea0 Run

🏁 Flaky tests

Some 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 /test/e2e/specs/editor/blocks/query.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 22
+ Received  +  1

  Array [
    Object {
-     "innerBlocks": Array [
-       Object {
-         "innerBlocks": Array [
-           Object {
-             "name": "core/post-title",
-           },
-           Object {
-             "name": "core/post-featured-image",
-           },
-           Object {
-             "name": "core/post-excerpt",
-           },
-           Object {
-             "name": "core/separator",
-           },
-           Object {
-             "name": "core/post-date",
-           },
-         ],
-         "name": "core/post-template",
-       },
-     ],
+     "innerBlocks": Array [],
      "name": "core/query",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/query.spec.js:226:42
should give the image its context menu while selected @WebKit @Firefox in /test/e2e/specs/editor/blocks/image.spec.js, passed after 1 failed attempt.
Test timeout of 100000ms exceeded.
should restore an older revision in /test/e2e/specs/editor/various/revisions.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

  Array [
    Object {
      "attributes": Object {
-       "content": "Original content - Updated content - Autosaved",
+       "content": "Original content",
      },
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/revisions.spec.js:146:5
should select synced pattern in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]') with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
    14 × locator resolved to <div tabindex="0" role="document" draggable="true" data-title="Pattern" data-type="core/block" data-is-drop-zone="true" aria-label="Block: Pattern" id="block-3bbffaff-53d1-460c-8d37-1ccadfbeb1ef" data-block="3bbffaff-53d1-460c-8d37-1ccadfbeb1ef" class="block-editor-block-list__block wp-block is-selected is-reusable block-library-block__reusable-block-container wp-block-block block-editor-block-list__layout">…</div>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:1464:5

10e4ea0 Run

@gziolo gziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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!

@jorgefilipecosta jorgefilipecosta added the Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 20, 2026
@jorgefilipecosta
jorgefilipecosta force-pushed the fix/abilities-uri-format-non-ascii-urls branch from bc3af32 to 76219b1 Compare November 20, 2026 18:04
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.
@jorgefilipecosta
jorgefilipecosta force-pushed the fix/abilities-uri-format-non-ascii-urls branch from 76219b1 to 10e4ea0 Compare November 20, 2026 18:38
@jorgefilipecosta
jorgefilipecosta merged commit 7293ead into trunk Nov 20, 2026
83 of 85 checks passed
@jorgefilipecosta
jorgefilipecosta deleted the fix/abilities-uri-format-non-ascii-urls branch November 20, 2026 23:08
@github-actions github-actions Bot added this to the Gutenberg 24.6 milestone Nov 20, 2026
@github-actions

Copy link
Copy Markdown

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.

# Checkout the wp/7.2 branch instead of trunk.
git checkout wp/7.2

# Create a new branch for your PR.
git checkout -b my-branch

# Cherry-pick the commit.
git cherry-pick 7293eaddcb15c6fb13125f72327c485199eb6d2e

# Check which files have conflicts.
git status

# Resolve the conflict...
# Add the resolved files to the staging area.
git status
git add .
git cherry-pick --continue

# Push the branch to the repository
git push origin my-branch

# Create a PR and set the base to the wp/7.2 branch.
# See https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request.

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

Labels

Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta [Package] Abilities /packages/abilities [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants