Commit a9bc71c0 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

strings: skip XML-invalid non-printable characters (fixes #15027)

parent 66315042
...@@ -82,8 +82,8 @@ int main (void) ...@@ -82,8 +82,8 @@ int main (void)
encode ("", ""); encode ("", "");
encode ("a'àc\"çe&én<ño>ö1:", "a&#39;àc&quot;çe&amp;én&lt;ño&gt;ö1:"); encode ("a'àc\"çe&én<ño>ö1:", "a&#39;àc&quot;çe&amp;én&lt;ño&gt;ö1:");
encode ("\x01\xC2\x81\xC2\x85", "&#1;&#129;\xC2\x85"); encode ("\xC2\x81\xC2\x85", "&#129;\xC2\x85");
encode ("\r\n", "\r\n"); encode (" \t\r\n", " \t\r\n");
return 0; return 0;
} }
...@@ -312,10 +312,6 @@ char *convert_xml_special_chars (const char *str) ...@@ -312,10 +312,6 @@ char *convert_xml_special_chars (const char *str)
return NULL; return NULL;
} }
if ((cp & ~0x0080) < 32 /* C0/C1 control codes */
&& memchr ("\x09\x0A\x0D\x85", cp, 4) == NULL)
ptr += sprintf (ptr, "&#%"PRIu32";", cp);
else
switch (cp) switch (cp)
{ {
case '\"': strcpy (ptr, "&quot;"); ptr += 6; break; case '\"': strcpy (ptr, "&quot;"); ptr += 6; break;
...@@ -323,7 +319,22 @@ char *convert_xml_special_chars (const char *str) ...@@ -323,7 +319,22 @@ char *convert_xml_special_chars (const char *str)
case '\'': strcpy (ptr, "&#39;"); ptr += 5; break; case '\'': strcpy (ptr, "&#39;"); ptr += 5; break;
case '<': strcpy (ptr, "&lt;"); ptr += 4; break; case '<': strcpy (ptr, "&lt;"); ptr += 4; break;
case '>': strcpy (ptr, "&gt;"); ptr += 4; break; case '>': strcpy (ptr, "&gt;"); ptr += 4; break;
default: memcpy (ptr, str, n); ptr += n; break; default:
if (cp < 32) /* C0 code not allowed (except 9, 10 and 13) */
break;
if (cp >= 128 && cp < 160) /* C1 code encoded (except 133) */
{
ptr += sprintf (ptr, "&#%"PRIu32";", cp);
break;
}
/* fall through */
case 9:
case 10:
case 13:
case 133:
memcpy (ptr, str, n);
ptr += n;
break;
} }
str += n; str += n;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment