Skip to content

Commit 474b13f

Browse files
authored
Added iswcntrl
1 parent c0a2f4f commit 474b13f

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

ext/standard/url.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <string.h>
1919
#include <ctype.h>
2020
#include <sys/types.h>
21+
#include <wchar.h>
2122

2223
#include "php.h"
2324

@@ -46,20 +47,22 @@ PHPAPI void php_url_free(php_url *theurl)
4647
efree(theurl);
4748
}
4849
/* }}} */
49-
50+
5051
static void php_replace_controlchars(char *str, size_t len)
5152
{
52-
unsigned char *s = (unsigned char *)str;
53-
unsigned char *e = (unsigned char *)str + len;
53+
assert(str != NULL);
5454

55-
ZEND_ASSERT(str != NULL);
55+
wchar_t wbuf[len];
56+
memset(wbuf, 0, sizeof(wbuf));
57+
size_t wlen = mbstowcs(wbuf, str, len);
5658

57-
while (s < e) {
58-
if (*s <= 0x1F || *s == 0x7F) {
59-
*s = '_';
60-
}
61-
s++;
62-
}
59+
for (size_t i = 0; i < wlen; i++) {
60+
if (iswcntrl(wbuf[i])) {
61+
wbuf[i] = L'_';
62+
}
63+
}
64+
65+
wcstombs(str, wbuf, len);
6366
}
6467

6568
PHPAPI php_url *php_url_parse(char const *str)

0 commit comments

Comments
 (0)