-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add ini_parse_quantity to convert ini directive "byte" shorthand to int #8454
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac03a9a
Add ini_bytes to translate ini directive byte shorthand to a count
dmsnell b7e3e5f
Rename parameter to "shorthand"
dmsnell 55b76e2
Rename function to `ini_parse_quantity( $shorthand )`
dmsnell 6ee5a87
Attempt to add basic tests for ini_parse_quantity()
dmsnell b840f14
Update tests to run successfully
dmsnell bf36ac1
Use zend_ini_parse_quantity
dmsnell ceda792
Add tests to test for warnings thrown
dmsnell 618a8e0
Regenerate arginfo
dmsnell 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
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,36 @@ | ||
--TEST-- | ||
ini_parse_quantity() function - basic test for ini_parse_quantity() | ||
--INI-- | ||
error_reporting = E_ALL ^ E_WARNING | ||
--FILE-- | ||
<?php | ||
foreach (array( | ||
'-1', | ||
'-0x412', | ||
'0', | ||
'1', | ||
'1b', | ||
'1k', | ||
'1m', | ||
'1g', | ||
'1gb', | ||
'14.2mb', | ||
'14.2bm', | ||
'boat' | ||
) as $input) { | ||
echo ini_parse_quantity( $input ) . PHP_EOL; | ||
} | ||
?> | ||
--EXPECT-- | ||
-1 | ||
-1042 | ||
0 | ||
1 | ||
1 | ||
1024 | ||
1048576 | ||
1073741824 | ||
1 | ||
14 | ||
14680064 | ||
0 | ||
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,14 @@ | ||
--TEST-- | ||
ini_parse_quantity() function - warns when given inappropriate values | ||
--INI-- | ||
error_reporting = E_ALL | ||
--FILE-- | ||
<?php | ||
ini_parse_quantity('-1'); | ||
ini_parse_quantity('1mb'); | ||
ini_parse_quantity('256 then skip a few then g') | ||
?> | ||
--EXPECTF-- | ||
Warning: Invalid quantity "1mb": unknown multipler "b", interpreting as "1" for backwards compatibility in %sini_parse_quantity_warnings.php on line 3 | ||
|
||
Warning: Invalid quantity "256 then skip a few then g", interpreting as "256 g" for backwards compatibility in %sini_parse_quantity_warnings.php on line 4 |
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.
This test looks good, but it'll fail. 😄
To run tests locally, use the
run-tests.php
script in the root of php-src. After you build PHP with your changes (usingmake
), you can run the test like this:Where
-p sapi/cli/php
is pointing to the new PHP executable that you just built that includes your changes.There are many options you can pass to
run-tests.php
. You can check them out by enteringphp run-tests.php -h
.When you have a failing test,
run-tests.php
will create a bunch of additional files in the same directory alongside your test file, which you can use for debugging.For example, when
tests/basic/ini_parse_quantity_basic.php
fails, you'll see the following new files created:Take a look at them to see what all they contain.
*.out
will tell you what the text actually printed out, while*.diff
will show a diff of what was expected vs. what was actually printed.For more information, check out the following:
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.
This is all great, and I'm quite happily surprised at how easy the testing setup is. Nothing wrong with test that fail before they succeed either 😄
These run locally for me, but I couldn't build them when I rebased against
master
(I think because of changes introduced in 8.1? Could not build PHP with the following error onmake
I'll try rebasing again in a work day or two as I presume this will be fixed upstream quickly (it's there for me in
master
anyway).Maybe I'll hold off on a more exhaustive test suite until the interplay with #7951 is clearer. The
zend_test_ini_parse_quantity
functions there I think could be renamed asini_parse_quantity
and replace this entire patch 🙃