mirror of
https://github.com/nginx/nginx.git
synced 2024-12-20 06:03:31 -06:00
ngx_escape_html()
This commit is contained in:
parent
0659720dc8
commit
1730c758a1
@ -1299,6 +1299,67 @@ done:
|
||||
}
|
||||
|
||||
|
||||
uintptr_t
|
||||
ngx_escape_html(u_char *dst, u_char *src, size_t size)
|
||||
{
|
||||
u_char ch;
|
||||
ngx_uint_t i, len;
|
||||
|
||||
if (dst == NULL) {
|
||||
|
||||
len = 0;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
switch (*src++) {
|
||||
|
||||
case '<':
|
||||
len += sizeof("<") - 2;
|
||||
break;
|
||||
|
||||
case '>':
|
||||
len += sizeof(">") - 2;
|
||||
break;
|
||||
|
||||
case '&':
|
||||
len += sizeof("&") - 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (uintptr_t) len;
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
ch = *src++;
|
||||
|
||||
switch (ch) {
|
||||
|
||||
case '<':
|
||||
*dst++ = '&'; *dst++ = 'l'; *dst++ = 't'; *dst++ = ';';
|
||||
break;
|
||||
|
||||
case '>':
|
||||
*dst++ = '&'; *dst++ = 'g'; *dst++ = 't'; *dst++ = ';';
|
||||
break;
|
||||
|
||||
case '&':
|
||||
*dst++ = '&'; *dst++ = 'a'; *dst++ = 'm'; *dst++ = 'p';
|
||||
*dst++ = ';';
|
||||
break;
|
||||
|
||||
default:
|
||||
*dst++ = ch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (uintptr_t) dst;
|
||||
}
|
||||
|
||||
|
||||
/* ngx_sort() is implemented as insertion sort because we need stable sort */
|
||||
|
||||
void
|
||||
|
@ -165,6 +165,8 @@ u_char *ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n);
|
||||
uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
|
||||
ngx_uint_t type);
|
||||
void ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type);
|
||||
uintptr_t ngx_escape_html(u_char *dst, u_char *src, size_t size);
|
||||
|
||||
|
||||
|
||||
void ngx_sort(void *base, size_t n, size_t size,
|
||||
|
Loading…
Reference in New Issue
Block a user