mirror of
https://github.com/michaelrsweet/mxml.git
synced 2025-05-09 22:52:07 +00:00
CHANGES:
- Changelog update. mxml-file.c: - Check for invalid control chars (STR #10) - Don't allow elements to contain duplicate attributes (STR #16) textmxml.c: - Add whitespace handling for CDATA elements. test.xml: - Add CDATA and comment data to test file.
This commit is contained in:
parent
166e301222
commit
8fc90a57d6
5
CHANGES
5
CHANGES
@ -3,6 +3,11 @@ CHANGES - 01/29/2005
|
|||||||
|
|
||||||
CHANGES IN Mini-XML 2.1.1
|
CHANGES IN Mini-XML 2.1.1
|
||||||
|
|
||||||
|
- mxmlLoad*() now returns an error when an XML stream
|
||||||
|
contains illegal control characters (STR #10)
|
||||||
|
- mxmlLoad*() now returns an error when an element
|
||||||
|
contains two attributes with the same name in
|
||||||
|
conformance with the XML spec (STR #16)
|
||||||
- Added support for CDATA (STR #14, STR #15)
|
- Added support for CDATA (STR #14, STR #15)
|
||||||
- Updated comment and processing instruction handling -
|
- Updated comment and processing instruction handling -
|
||||||
no entity support per XML specification.
|
no entity support per XML specification.
|
||||||
|
100
mxml-file.c
100
mxml-file.c
@ -66,6 +66,13 @@
|
|||||||
#define ENCODE_UTF16LE 2 /* UTF-16 Little-Endian */
|
#define ENCODE_UTF16LE 2 /* UTF-16 Little-Endian */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Macro to test for a bad XML character...
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define mxml_bad_char(ch) ((ch) < ' ' && (ch) != '\n' && (ch) != '\r' && (ch) != '\t')
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* File descriptor buffer...
|
* File descriptor buffer...
|
||||||
*/
|
*/
|
||||||
@ -578,8 +585,21 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (!(ch & 0x80))
|
if (!(ch & 0x80))
|
||||||
|
{
|
||||||
|
#if DEBUG > 1
|
||||||
|
printf("mxml_fd_getc: %c (0x%04x)\n", ch < ' ' ? '.' : ch, ch);
|
||||||
|
#endif /* DEBUG > 1 */
|
||||||
|
|
||||||
|
if (mxml_bad_char(ch))
|
||||||
|
{
|
||||||
|
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||||
|
ch);
|
||||||
|
return (EOF);
|
||||||
|
}
|
||||||
|
|
||||||
return (ch);
|
return (ch);
|
||||||
else if (ch == 0xfe)
|
}
|
||||||
|
else if (ch == 0xfe)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* UTF-16 big-endian BOM?
|
* UTF-16 big-endian BOM?
|
||||||
@ -727,7 +747,13 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
|
|||||||
|
|
||||||
ch = (ch << 8) | temp;
|
ch = (ch << 8) | temp;
|
||||||
|
|
||||||
if (ch >= 0xd800 && ch <= 0xdbff)
|
if (mxml_bad_char(ch))
|
||||||
|
{
|
||||||
|
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||||
|
ch);
|
||||||
|
return (EOF);
|
||||||
|
}
|
||||||
|
else if (ch >= 0xd800 && ch <= 0xdbff)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Multi-word UTF-16 char...
|
* Multi-word UTF-16 char...
|
||||||
@ -769,7 +795,13 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
|
|||||||
|
|
||||||
ch |= (temp << 8);
|
ch |= (temp << 8);
|
||||||
|
|
||||||
if (ch >= 0xd800 && ch <= 0xdbff)
|
if (mxml_bad_char(ch))
|
||||||
|
{
|
||||||
|
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||||
|
ch);
|
||||||
|
return (EOF);
|
||||||
|
}
|
||||||
|
else if (ch >= 0xd800 && ch <= 0xdbff)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Multi-word UTF-16 char...
|
* Multi-word UTF-16 char...
|
||||||
@ -799,6 +831,10 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG > 1
|
||||||
|
printf("mxml_fd_getc: %c (0x%04x)\n", ch < ' ' ? '.' : ch, ch);
|
||||||
|
#endif /* DEBUG > 1 */
|
||||||
|
|
||||||
return (ch);
|
return (ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -986,6 +1022,13 @@ mxml_file_getc(void *p, /* I - Pointer to file */
|
|||||||
|
|
||||||
if (!(ch & 0x80))
|
if (!(ch & 0x80))
|
||||||
{
|
{
|
||||||
|
if (mxml_bad_char(ch))
|
||||||
|
{
|
||||||
|
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||||
|
ch);
|
||||||
|
return (EOF);
|
||||||
|
}
|
||||||
|
|
||||||
#if DEBUG > 1
|
#if DEBUG > 1
|
||||||
printf("mxml_file_getc: %c (0x%04x)\n", ch < ' ' ? '.' : ch, ch);
|
printf("mxml_file_getc: %c (0x%04x)\n", ch < ' ' ? '.' : ch, ch);
|
||||||
#endif /* DEBUG > 1 */
|
#endif /* DEBUG > 1 */
|
||||||
@ -1088,7 +1131,13 @@ mxml_file_getc(void *p, /* I - Pointer to file */
|
|||||||
|
|
||||||
ch = (ch << 8) | getc(fp);
|
ch = (ch << 8) | getc(fp);
|
||||||
|
|
||||||
if (ch >= 0xd800 && ch <= 0xdbff)
|
if (mxml_bad_char(ch))
|
||||||
|
{
|
||||||
|
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||||
|
ch);
|
||||||
|
return (EOF);
|
||||||
|
}
|
||||||
|
else if (ch >= 0xd800 && ch <= 0xdbff)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Multi-word UTF-16 char...
|
* Multi-word UTF-16 char...
|
||||||
@ -1110,7 +1159,13 @@ mxml_file_getc(void *p, /* I - Pointer to file */
|
|||||||
|
|
||||||
ch |= (getc(fp) << 8);
|
ch |= (getc(fp) << 8);
|
||||||
|
|
||||||
if (ch >= 0xd800 && ch <= 0xdbff)
|
if (mxml_bad_char(ch))
|
||||||
|
{
|
||||||
|
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||||
|
ch);
|
||||||
|
return (EOF);
|
||||||
|
}
|
||||||
|
else if (ch >= 0xd800 && ch <= 0xdbff)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Multi-word UTF-16 char...
|
* Multi-word UTF-16 char...
|
||||||
@ -1239,6 +1294,13 @@ mxml_get_entity(mxml_node_t *parent, /* I - Parent node */
|
|||||||
mxml_error("Entity name \"%s;\" not supported under parent <%s>!",
|
mxml_error("Entity name \"%s;\" not supported under parent <%s>!",
|
||||||
entity, parent ? parent->value.element.name : "null");
|
entity, parent ? parent->value.element.name : "null");
|
||||||
|
|
||||||
|
if (mxml_bad_char(ch))
|
||||||
|
{
|
||||||
|
mxml_error("Bad control character 0x%02x under parent <%s> not allowed by XML standard!",
|
||||||
|
ch, parent ? parent->value.element.name : "null");
|
||||||
|
return (EOF);
|
||||||
|
}
|
||||||
|
|
||||||
return (ch);
|
return (ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1856,6 +1918,9 @@ mxml_parse_element(mxml_node_t *node, /* I - Element node */
|
|||||||
|
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
|
||||||
|
if (mxmlElementGetAttr(node, name))
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (ch == '=')
|
if (ch == '=')
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -2011,8 +2076,15 @@ mxml_string_getc(void *p, /* I - Pointer to file */
|
|||||||
printf("mxml_string_getc: %c (0x%04x)\n", ch < ' ' ? '.' : ch, ch);
|
printf("mxml_string_getc: %c (0x%04x)\n", ch < ' ' ? '.' : ch, ch);
|
||||||
#endif /* DEBUG > 1 */
|
#endif /* DEBUG > 1 */
|
||||||
|
|
||||||
|
if (mxml_bad_char(ch))
|
||||||
|
{
|
||||||
|
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||||
|
ch);
|
||||||
|
return (EOF);
|
||||||
|
}
|
||||||
|
|
||||||
return (ch);
|
return (ch);
|
||||||
}
|
}
|
||||||
else if (ch == 0xfe)
|
else if (ch == 0xfe)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -2122,7 +2194,13 @@ mxml_string_getc(void *p, /* I - Pointer to file */
|
|||||||
ch = (ch << 8) | ((*s)[0] & 255);
|
ch = (ch << 8) | ((*s)[0] & 255);
|
||||||
(*s) ++;
|
(*s) ++;
|
||||||
|
|
||||||
if (ch >= 0xd800 && ch <= 0xdbff)
|
if (mxml_bad_char(ch))
|
||||||
|
{
|
||||||
|
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||||
|
ch);
|
||||||
|
return (EOF);
|
||||||
|
}
|
||||||
|
else if (ch >= 0xd800 && ch <= 0xdbff)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Multi-word UTF-16 char...
|
* Multi-word UTF-16 char...
|
||||||
@ -2164,7 +2242,13 @@ mxml_string_getc(void *p, /* I - Pointer to file */
|
|||||||
|
|
||||||
(*s) ++;
|
(*s) ++;
|
||||||
|
|
||||||
if (ch >= 0xd800 && ch <= 0xdbff)
|
if (mxml_bad_char(ch))
|
||||||
|
{
|
||||||
|
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||||
|
ch);
|
||||||
|
return (EOF);
|
||||||
|
}
|
||||||
|
else if (ch >= 0xd800 && ch <= 0xdbff)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Multi-word UTF-16 char...
|
* Multi-word UTF-16 char...
|
||||||
|
2
test.xml
2
test.xml
@ -24,4 +24,6 @@
|
|||||||
<integer>123</integer>
|
<integer>123</integer>
|
||||||
<string>Now is the time for all good men to come to the aid of their
|
<string>Now is the time for all good men to come to the aid of their
|
||||||
country.</string>
|
country.</string>
|
||||||
|
<!-- this is a comment -->
|
||||||
|
<![CDATA[this is CDATA 0123456789ABCDEF]]>
|
||||||
</group>
|
</group>
|
||||||
|
@ -634,7 +634,7 @@ whitespace_cb(mxml_node_t *node, /* I - Element node */
|
|||||||
!strcmp(name, "choice")) &&
|
!strcmp(name, "choice")) &&
|
||||||
where == MXML_WS_AFTER_OPEN))
|
where == MXML_WS_AFTER_OPEN))
|
||||||
return ("\n");
|
return ("\n");
|
||||||
else if (!strcmp(name, "code") && where == MXML_WS_AFTER_OPEN && !node->child)
|
else if (where == MXML_WS_AFTER_OPEN && !node->child)
|
||||||
return ("\n");
|
return ("\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user