Skip to content

Commit

Permalink
ext/standard/url.c: Stop exposing php_replace_controlchars_ex()
Browse files Browse the repository at this point in the history
This is not used from a quick search on SourceGraph and this allows us to refactor it
  • Loading branch information
Girgias committed Sep 12, 2024
1 parent d45eb46 commit 8109d21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
1 change: 1 addition & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ PHP 8.4 INTERNALS UPGRADE NOTES
php_string_tolower() functions has been removed, use zend_str_toupper(),
zend_string_toupper(), zend_str_tolower(), and zend_string_tolower()
respectively instead.
- The php_replace_controlchars_ex() function is no longer exposed.

h. ext/session
- Added the php_get_session_status() API to get the session status, which is
Expand Down
36 changes: 12 additions & 24 deletions ext/standard/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,19 @@ PHPAPI void php_url_free(php_url *theurl)
}
/* }}} */

/* {{{ php_replace_controlchars_ex */
PHPAPI char *php_replace_controlchars_ex(char *str, size_t len)
static void php_replace_controlchars(char *str, size_t len)
{
unsigned char *s = (unsigned char *)str;
unsigned char *e = (unsigned char *)str + len;

if (!str) {
return (NULL);
}
ZEND_ASSERT(str != NULL);

while (s < e) {

if (iscntrl(*s)) {
*s='_';
}
s++;
}

return (str);
}
/* }}} */

PHPAPI char *php_replace_controlchars(char *str)
{
return php_replace_controlchars_ex(str, strlen(str));
}

PHPAPI php_url *php_url_parse(char const *str)
Expand Down Expand Up @@ -133,7 +121,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port

if (e + 1 == ue) { /* only scheme is available */
ret->scheme = zend_string_init(s, (e - s), 0);
php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme));
php_replace_controlchars(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme));
return ret;
}

Expand All @@ -155,13 +143,13 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
}

ret->scheme = zend_string_init(s, (e-s), 0);
php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme));
php_replace_controlchars(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme));

s = e + 1;
goto just_path;
} else {
ret->scheme = zend_string_init(s, (e-s), 0);
php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme));
php_replace_controlchars(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme));

if (e + 2 < ue && *(e + 2) == '/') {
s = e + 3;
Expand Down Expand Up @@ -227,14 +215,14 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
if ((p = zend_memrchr(s, '@', (e-s)))) {
if ((pp = memchr(s, ':', (p-s)))) {
ret->user = zend_string_init(s, (pp-s), 0);
php_replace_controlchars_ex(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user));
php_replace_controlchars(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user));

pp++;
ret->pass = zend_string_init(pp, (p-pp), 0);
php_replace_controlchars_ex(ZSTR_VAL(ret->pass), ZSTR_LEN(ret->pass));
php_replace_controlchars(ZSTR_VAL(ret->pass), ZSTR_LEN(ret->pass));
} else {
ret->user = zend_string_init(s, (p-s), 0);
php_replace_controlchars_ex(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user));
php_replace_controlchars(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user));
}

s = p + 1;
Expand Down Expand Up @@ -283,7 +271,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
}

ret->host = zend_string_init(s, (p-s), 0);
php_replace_controlchars_ex(ZSTR_VAL(ret->host), ZSTR_LEN(ret->host));
php_replace_controlchars(ZSTR_VAL(ret->host), ZSTR_LEN(ret->host));

if (e == ue) {
return ret;
Expand All @@ -299,7 +287,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
p++;
if (p < e) {
ret->fragment = zend_string_init(p, (e - p), 0);
php_replace_controlchars_ex(ZSTR_VAL(ret->fragment), ZSTR_LEN(ret->fragment));
php_replace_controlchars(ZSTR_VAL(ret->fragment), ZSTR_LEN(ret->fragment));
} else {
ret->fragment = ZSTR_EMPTY_ALLOC();
}
Expand All @@ -311,7 +299,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
p++;
if (p < e) {
ret->query = zend_string_init(p, (e - p), 0);
php_replace_controlchars_ex(ZSTR_VAL(ret->query), ZSTR_LEN(ret->query));
php_replace_controlchars(ZSTR_VAL(ret->query), ZSTR_LEN(ret->query));
} else {
ret->query = ZSTR_EMPTY_ALLOC();
}
Expand All @@ -320,7 +308,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port

if (s < e || s == ue) {
ret->path = zend_string_init(s, (e - s), 0);
php_replace_controlchars_ex(ZSTR_VAL(ret->path), ZSTR_LEN(ret->path));
php_replace_controlchars(ZSTR_VAL(ret->path), ZSTR_LEN(ret->path));
}

return ret;
Expand Down
1 change: 0 additions & 1 deletion ext/standard/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ PHPAPI size_t php_url_decode(char *str, size_t len); /* return value: length of
PHPAPI size_t php_raw_url_decode(char *str, size_t len); /* return value: length of decoded string */
PHPAPI zend_string *php_url_encode(char const *s, size_t len);
PHPAPI zend_string *php_raw_url_encode(char const *s, size_t len);
PHPAPI char *php_replace_controlchars_ex(char *str, size_t len);

#define PHP_URL_SCHEME 0
#define PHP_URL_HOST 1
Expand Down

0 comments on commit 8109d21

Please sign in to comment.