Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3715,7 +3715,7 @@ function parse_url(string $url, int $component = -1): int|string|array|null|fals
* @compile-time-eval
* @refcount 1
*/
function urlencode(string $string): string {}
function urlencode(string|int $string): string {}

/**
* @compile-time-eval
Expand All @@ -3727,7 +3727,7 @@ function urldecode(string $string): string {}
* @compile-time-eval
* @refcount 1
*/
function rawurlencode(string $string): string {}
function rawurlencode(string|int $string): string {}

/**
* @compile-time-eval
Expand Down
8 changes: 5 additions & 3 deletions ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 41 additions & 10 deletions ext/standard/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,13 +552,28 @@ PHPAPI zend_string *php_url_encode(char const *s, size_t len)
/* {{{ URL-encodes string */
PHP_FUNCTION(urlencode)
{
zend_string *in_str;
zend_string *in_str = NULL;
zend_long in_long;
zend_string *tmpstr = NULL;
zend_string *encoded_str;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(in_str)
ZEND_PARSE_PARAMETERS_END();
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR_OR_LONG(in_str, in_long)
ZEND_PARSE_PARAMETERS_END();

if (in_str == NULL) {
/* Input is an integer */
in_str = tmpstr = zend_long_to_str(in_long);
}

RETURN_STR(php_url_encode(ZSTR_VAL(in_str), ZSTR_LEN(in_str)));
encoded_str = php_url_encode(ZSTR_VAL(in_str), ZSTR_LEN(in_str));

/* Release the temporary string if we allocated one */
if (tmpstr != NULL) {
zend_string_release(tmpstr);
}

RETURN_STR(encoded_str);
}
/* }}} */

Expand Down Expand Up @@ -614,13 +629,29 @@ PHPAPI zend_string *php_raw_url_encode(char const *s, size_t len)
/* {{{ URL-encodes string */
PHP_FUNCTION(rawurlencode)
{
zend_string *in_str;
zend_string *in_str = NULL;
zend_long in_long;
zend_string *tmpstr = NULL;
zend_string *encoded_str;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(in_str)
ZEND_PARSE_PARAMETERS_END();
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR_OR_LONG(in_str, in_long)
ZEND_PARSE_PARAMETERS_END();

if (in_str == NULL) {
/* Input is an integer */
in_str = tmpstr = zend_long_to_str(in_long);
}

encoded_str = php_raw_url_encode(ZSTR_VAL(in_str), ZSTR_LEN(in_str));


/* Release the temporary string if we allocated one */
if (tmpstr != NULL) {
zend_string_release(tmpstr);
}

RETURN_STR(php_raw_url_encode(ZSTR_VAL(in_str), ZSTR_LEN(in_str)));
RETURN_STR(encoded_str);
}
/* }}} */

Expand Down
10 changes: 9 additions & 1 deletion tests/strings/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
String functions
--FILE--
<?php

declare(strict_types=1);
echo "Testing strtok: ";

$str = "testing 1/2\\3";
Expand Down Expand Up @@ -202,6 +202,11 @@ if (strlen($ui1) == strlen($ui2) && strlen($ui1) == $len && $ui1 != $ui2) {
echo("failed!\n");
}

echo "testing (raw)urlencode(int)\n";
var_dump(urlencode(1));
var_dump(rawurlencode(1));


?>
--EXPECT--
Testing strtok: passed
Expand All @@ -221,3 +226,6 @@ Testing addslashes: passed
Testing stripslashes: passed
Testing uniqid(true): passed
Testing uniqid(false): passed
testing (raw)urlencode(int)
string(1) "1"
string(1) "1"
Loading