Skip to content

Tests: Add unit test coverage for wp_kses_allow_pdf_objects() - #14666

Open
shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:65819/tests-wp-kses-allow-pdf-objects
Open

shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:65819/tests-wp-kses-allow-pdf-objects

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

What

Trac ticket: #65819

Adds unit tests for _wp_kses_allow_pdf_objects() in tests/phpunit/tests/kses/wpKsesAllowPdfObjects.php.

Why

_wp_kses_allow_pdf_objects() has no dedicated unit tests. Adding coverage for this helper fills that gap under #65819.

How

New test class covering:

  • rejection of query strings and fragments
  • rejection of non-PDF extensions
  • rejection of PDFs from other hosts
  • acceptance of PDFs under the site uploads URL

Test-only; no production code changes.

Testing Instructions

  1. npm run test:php -- --filter Tests_Kses_wpKsesAllowPdfObjects
  2. npm run test:php -- --filter Tests_Kses_wpKsesAllowPdfObjects -c tests/phpunit/multisite.xml
  3. npm run test:php -- --filter Tests_Kses_wpKsesAllowPdfObjects --order-by=random
  4. npm run test:php -- --group kses

Use of AI Tools

  • Cursor

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The query-string and fragment fixtures need to isolate their intended rejection checks to detect regressions.

1 open issue
What changed in this PR

Adds dedicated unit tests for _wp_kses_allow_pdf_objects() under Trac #65819, without changing production code.

Changes:

  • Tests rejection of query strings, fragments, non-PDF extensions, and other hosts.
  • Tests acceptance of PDFs under the site uploads URL.
File Description
tests/​phpunit/​tests/​kses/​wpKsesAllowPdfObjects.php Adds five dedicated PDF-object validation tests.

Review effort: Balanced

Comment thread tests/phpunit/tests/kses/wpKsesAllowPdfObjects.php Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Static review found the assertions consistent with the helper’s behavior and no blocking issues; tests were not executed.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review October 21, 2026 17:54
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shailu25.

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

@mukeshpanchal27 mukeshpanchal27 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.

Thanks for the tests. They look correct, and CI passes. One optional suggestion inline.

* @ticket 65819
*/
public function test_rejects_pdf_from_other_host() {
$this->assertFalse( _wp_kses_allow_pdf_objects( 'https://evil.example/file.pdf' ) );

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.

Optional: a host-prefix case would lock in the trailing / in the str_starts_with() check. A URL such as https://<uploads host>.evil.example/file.pdf should return false:

$host = wp_parse_url( wp_upload_dir( null, false )['url'], PHP_URL_HOST );

$this->assertFalse( _wp_kses_allow_pdf_objects( 'https://' . $host . '.evil.example/file.pdf' ) );

Also, the PR title says wp_kses_allow_pdf_objects(), but the function is _wp_kses_allow_pdf_objects().

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.

3 participants