Repository navigation
Tests: Add unit test coverage for wp_kses_allow_pdf_objects() - #14666
shail-mehta wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 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
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
mukeshpanchal27
left a comment
There was a problem hiding this comment.
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' ) ); |
There was a problem hiding this comment.
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().

What
Trac ticket: #65819
Adds unit tests for
_wp_kses_allow_pdf_objects()intests/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:
Test-only; no production code changes.
Testing Instructions
npm run test:php -- --filter Tests_Kses_wpKsesAllowPdfObjectsnpm run test:php -- --filter Tests_Kses_wpKsesAllowPdfObjects -c tests/phpunit/multisite.xmlnpm run test:php -- --filter Tests_Kses_wpKsesAllowPdfObjects --order-by=randomnpm run test:php -- --group ksesUse of AI Tools