Skip to content

Tests: Add tests for extracting and adding empty files with PclZip. - #14894

Open
irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:task/52018-pclzip-empty-files-tests
Open

irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:task/52018-pclzip-empty-files-tests

Conversation

@irozum

@irozum irozum commented Oct 26, 2026

Copy link
Copy Markdown

Summary

  • Adds unit tests for how PclZip handles zero-byte entries. On PHP 8, fread( $fd, 0 ) throws a ValueError, which @ doesn't suppress.
  • This is test-only. It changes nothing under src/ and adds no production behaviour.
  • Follow-up to [50355] and [51686], which added the zero-length guards in class-pclzip.php without tests.

Tests added

  • Tests_Filesystem_UnzipFilePclzip::test_should_extract_empty_files() runs _unzip_file_pclzip() on the existing archive.zip fixture, which has two zero-byte stored files. It asserts both are extracted and empty. This covers the privExtractFileAsString() guard. The existing tests only checked filter calls.
  • Tests_Filesystem_PclZip::test_extract_in_output_should_output_empty_file() extracts an empty entry with PCLZIP_OPT_EXTRACT_IN_OUTPUT. It asserts no output and a correct entry. This covers the privExtractFileInOutput() guard, which nothing exercised before.
  • Tests_Filesystem_PclZip::test_create_should_add_empty_file() creates an archive from an empty file (with PCLZIP_OPT_TEMP_FILE_OFF, to reach the in-memory branch) and reads it back. This covers the privAddFile() guard from #54036.

Why these cases

Each test fails with ValueError: fread(): Argument #2 ($length) must be greater than 0 when its guard is reverted (> 0 changed to >= 0), and passes with the guard restored. On PHP 7.4 fread() only warns, so the behavioural assertions hold there too.

Trac ticket: https://core.trac.wordpress.org/ticket/52018

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Drafting the tests and this description, and running the mutation checks and coding-standards checks.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

🤖 Generated with Claude Code

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

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

Props irozum.

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.

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.

1 participant