Skip to content

Commit 8109d21

Browse files
committed
ext/standard/url.c: Stop exposing php_replace_controlchars_ex()
This is not used from a quick search on SourceGraph and this allows us to refactor it
1 parent d45eb46 commit 8109d21

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

UPGRADING.INTERNALS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ PHP 8.4 INTERNALS UPGRADE NOTES
380380
php_string_tolower() functions has been removed, use zend_str_toupper(),
381381
zend_string_toupper(), zend_str_tolower(), and zend_string_tolower()
382382
respectively instead.
383+
- The php_replace_controlchars_ex() function is no longer exposed.
383384

384385
h. ext/session
385386
- Added the php_get_session_status() API to get the session status, which is

ext/standard/url.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,19 @@ PHPAPI void php_url_free(php_url *theurl)
4949
}
5050
/* }}} */
5151

52-
/* {{{ php_replace_controlchars_ex */
53-
PHPAPI char *php_replace_controlchars_ex(char *str, size_t len)
52+
static void php_replace_controlchars(char *str, size_t len)
5453
{
5554
unsigned char *s = (unsigned char *)str;
5655
unsigned char *e = (unsigned char *)str + len;
5756

58-
if (!str) {
59-
return (NULL);
60-
}
57+
ZEND_ASSERT(str != NULL);
6158

6259
while (s < e) {
63-
6460
if (iscntrl(*s)) {
6561
*s='_';
6662
}
6763
s++;
6864
}
69-
70-
return (str);
71-
}
72-
/* }}} */
73-
74-
PHPAPI char *php_replace_controlchars(char *str)
75-
{
76-
return php_replace_controlchars_ex(str, strlen(str));
7765
}
7866

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

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

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

157145
ret->scheme = zend_string_init(s, (e-s), 0);
158-
php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme));
146+
php_replace_controlchars(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme));
159147

160148
s = e + 1;
161149
goto just_path;
162150
} else {
163151
ret->scheme = zend_string_init(s, (e-s), 0);
164-
php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme));
152+
php_replace_controlchars(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme));
165153

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

232220
pp++;
233221
ret->pass = zend_string_init(pp, (p-pp), 0);
234-
php_replace_controlchars_ex(ZSTR_VAL(ret->pass), ZSTR_LEN(ret->pass));
222+
php_replace_controlchars(ZSTR_VAL(ret->pass), ZSTR_LEN(ret->pass));
235223
} else {
236224
ret->user = zend_string_init(s, (p-s), 0);
237-
php_replace_controlchars_ex(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user));
225+
php_replace_controlchars(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user));
238226
}
239227

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

285273
ret->host = zend_string_init(s, (p-s), 0);
286-
php_replace_controlchars_ex(ZSTR_VAL(ret->host), ZSTR_LEN(ret->host));
274+
php_replace_controlchars(ZSTR_VAL(ret->host), ZSTR_LEN(ret->host));
287275

288276
if (e == ue) {
289277
return ret;
@@ -299,7 +287,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
299287
p++;
300288
if (p < e) {
301289
ret->fragment = zend_string_init(p, (e - p), 0);
302-
php_replace_controlchars_ex(ZSTR_VAL(ret->fragment), ZSTR_LEN(ret->fragment));
290+
php_replace_controlchars(ZSTR_VAL(ret->fragment), ZSTR_LEN(ret->fragment));
303291
} else {
304292
ret->fragment = ZSTR_EMPTY_ALLOC();
305293
}
@@ -311,7 +299,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
311299
p++;
312300
if (p < e) {
313301
ret->query = zend_string_init(p, (e - p), 0);
314-
php_replace_controlchars_ex(ZSTR_VAL(ret->query), ZSTR_LEN(ret->query));
302+
php_replace_controlchars(ZSTR_VAL(ret->query), ZSTR_LEN(ret->query));
315303
} else {
316304
ret->query = ZSTR_EMPTY_ALLOC();
317305
}
@@ -320,7 +308,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
320308

321309
if (s < e || s == ue) {
322310
ret->path = zend_string_init(s, (e - s), 0);
323-
php_replace_controlchars_ex(ZSTR_VAL(ret->path), ZSTR_LEN(ret->path));
311+
php_replace_controlchars(ZSTR_VAL(ret->path), ZSTR_LEN(ret->path));
324312
}
325313

326314
return ret;

ext/standard/url.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ PHPAPI size_t php_url_decode(char *str, size_t len); /* return value: length of
3636
PHPAPI size_t php_raw_url_decode(char *str, size_t len); /* return value: length of decoded string */
3737
PHPAPI zend_string *php_url_encode(char const *s, size_t len);
3838
PHPAPI zend_string *php_raw_url_encode(char const *s, size_t len);
39-
PHPAPI char *php_replace_controlchars_ex(char *str, size_t len);
4039

4140
#define PHP_URL_SCHEME 0
4241
#define PHP_URL_HOST 1

0 commit comments

Comments
 (0)