mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
add_html_to_string: Encode only known unsafe or non-ASCII characters.
In particular, do not encode '%' and '/', which are common in URIs.
This commit is contained in:
parent
3ee04479d4
commit
36dd1fa267
@ -274,22 +274,18 @@ add_string_replace(struct string *string, unsigned char *src, int len,
|
|||||||
struct string *
|
struct string *
|
||||||
add_html_to_string(struct string *string, const unsigned char *src, int len)
|
add_html_to_string(struct string *string, const unsigned char *src, int len)
|
||||||
{
|
{
|
||||||
|
|
||||||
#define isalphanum(q) (isalnum(q) || (q) == '-' || (q) == '_')
|
|
||||||
|
|
||||||
for (; len; len--, src++) {
|
for (; len; len--, src++) {
|
||||||
if (isalphanum(*src) || *src == ' '
|
if (*src < 0x20 || *src >= 0x7F
|
||||||
|| *src == '.' || *src == ':' || *src == ';') {
|
|| *src == '<' || *src == '>' || *src == '&'
|
||||||
add_bytes_to_string(string, src, 1);
|
|| *src == '\"' || *src == '\'') {
|
||||||
} else {
|
|
||||||
add_bytes_to_string(string, "&#", 2);
|
add_bytes_to_string(string, "&#", 2);
|
||||||
add_long_to_string(string, (long) *src);
|
add_long_to_string(string, (long) *src);
|
||||||
add_char_to_string(string, ';');
|
add_char_to_string(string, ';');
|
||||||
|
} else {
|
||||||
|
add_char_to_string(string, *src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef isalphanum
|
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user