-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add ZipArchive::closeString() #21497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tstarling
wants to merge
1
commit into
php:master
Choose a base branch
from
tstarling:ZipArchive-closeToString
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --TEST-- | ||
| ZipArchive::closeString() basic | ||
| --EXTENSIONS-- | ||
| zip | ||
| --FILE-- | ||
| <?php | ||
| $zip = new ZipArchive(); | ||
| $zip->openString(); | ||
| $zip->addFromString('test1', '1'); | ||
| $zip->addFromString('test2', '2'); | ||
| $contents = $zip->closeString(); | ||
| echo $contents ? "OK\n" : "FAILED\n"; | ||
|
|
||
| $zip = new ZipArchive(); | ||
| $zip->openString($contents); | ||
| var_dump($zip->getFromName('test1')); | ||
| var_dump($zip->getFromName('test2')); | ||
| var_dump($zip->getFromName('nonexistent')); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| OK | ||
| string(1) "1" | ||
| string(1) "2" | ||
| bool(false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| --TEST-- | ||
| ZipArchive::closeString() error cases | ||
| --EXTENSIONS-- | ||
| zip | ||
| --FILE-- | ||
| <?php | ||
| echo "1.\n"; | ||
| $zip = new ZipArchive(); | ||
| $zip->openString(); | ||
| var_dump($zip->open(__DIR__ . '/test.zip')); | ||
| try { | ||
| $zip->closeString(); | ||
| } catch (Error $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
|
|
||
| echo "2.\n"; | ||
| $zip = new ZipArchive(); | ||
| $zip->openString('...'); | ||
| echo $zip->getStatusString() . "\n"; | ||
| try { | ||
| $zip->closeString(); | ||
| } catch (Error $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
|
|
||
| echo "3.\n"; | ||
| $zip = new ZipArchive(); | ||
| $zip->openString(file_get_contents(__DIR__ . '/test.zip')); | ||
| echo gettype($zip->closeString()) . "\n"; | ||
| try { | ||
| $zip->closeString(); | ||
| } catch (Error $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| 1. | ||
| bool(true) | ||
| ZipArchive::closeString can only be called on an archive opened with ZipArchive::openString | ||
| 2. | ||
| Not a zip archive | ||
| Invalid or uninitialized Zip object | ||
| 3. | ||
| string | ||
| Invalid or uninitialized Zip object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --TEST-- | ||
| ZipArchive::closeString() false return | ||
| --EXTENSIONS-- | ||
| zip | ||
| --FILE-- | ||
| <?php | ||
| $zip = new ZipArchive(); | ||
| // The "compressed size" fields are wrong, causing an error when reading the contents. | ||
| // The error is reported on close when we rewrite the member with setCompressionIndex(). | ||
| // The error code is ER_DATA_LENGTH in libzip 1.10.0+ or ER_INCONS otherwise. | ||
| $input = file_get_contents(__DIR__ . '/wrong-file-size.zip'); | ||
| var_dump($zip->openString($input)); | ||
| $zip->setCompressionIndex(0, ZipArchive::CM_DEFLATE); | ||
| var_dump($zip->closeString()); | ||
| echo $zip->getStatusString() . "\n"; | ||
| ?> | ||
| --EXPECTREGEX-- | ||
| bool\(true\) | ||
|
|
||
| Warning: ZipArchive::closeString\(\): (Zip archive inconsistent|Unexpected length of data).* | ||
| bool\(false\) | ||
| (Zip archive inconsistent|Unexpected length of data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| --TEST-- | ||
| ZipArchive::closeString() variations | ||
|
DanielEScherzer marked this conversation as resolved.
|
||
| --EXTENSIONS-- | ||
| zip | ||
| --FILE-- | ||
| <?php | ||
| echo "1. Empty archive creation\n"; | ||
| $zip = new ZipArchive(); | ||
| $zip->openString(); | ||
| var_dump($zip->closeString()); | ||
| echo $zip->getStatusString() . "\n"; | ||
|
|
||
| echo "2. Update existing archive\n"; | ||
| $input = file_get_contents(__DIR__ . '/test.zip'); | ||
| $zip = new ZipArchive(); | ||
| $zip->openString($input); | ||
| $zip->addFromString('entry1.txt', ''); | ||
| $result = $zip->closeString(); | ||
| echo gettype($result) . "\n"; | ||
| var_dump($input !== $result); | ||
| ?> | ||
| --EXPECT-- | ||
| 1. Empty archive creation | ||
| string(0) "" | ||
| No error | ||
| 2. Update existing archive | ||
| string | ||
| bool(true) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
obj->out_stris not set, we should ensure that callers do not try to use theout_str, suggest addingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to revert this, since the assertion fails when closeString() is called but something goes wrong with saving the archive. The caller is already guarding for that, and false is returned to userspace. There was already a test, which failed due to the assertion.