mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-09 04:58:16 +03:00
parser: Ignore cdata argument in xmlParseCharData
It never could be used to parse CDATA sections.
This commit is contained in:
parent
e4f56a7213
commit
f00739c12e
252
parser.c
252
parser.c
@ -4380,7 +4380,7 @@ xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) {
|
||||
return(buf);
|
||||
}
|
||||
|
||||
static void xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata);
|
||||
static void xmlParseCharDataComplex(xmlParserCtxtPtr ctxt);
|
||||
|
||||
/*
|
||||
* used for the test in the inner loop of the char data testing
|
||||
@ -4423,7 +4423,7 @@ static const unsigned char test_char_data[256] = {
|
||||
/**
|
||||
* xmlParseCharData:
|
||||
* @ctxt: an XML parser context
|
||||
* @cdata: int indicating whether we are within a CDATA section
|
||||
* @cdata: unused
|
||||
*
|
||||
* DEPRECATED: Internal function, don't use.
|
||||
*
|
||||
@ -4441,7 +4441,7 @@ static const unsigned char test_char_data[256] = {
|
||||
*/
|
||||
|
||||
void
|
||||
xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) {
|
||||
xmlParseCharData(xmlParserCtxtPtr ctxt, ATTRIBUTE_UNUSED int cdata) {
|
||||
const xmlChar *in;
|
||||
int nbchar = 0;
|
||||
int line = ctxt->input->line;
|
||||
@ -4454,132 +4454,130 @@ xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) {
|
||||
* Accelerated common case where input don't need to be
|
||||
* modified before passing it to the handler.
|
||||
*/
|
||||
if (!cdata) {
|
||||
in = ctxt->input->cur;
|
||||
do {
|
||||
in = ctxt->input->cur;
|
||||
do {
|
||||
get_more_space:
|
||||
while (*in == 0x20) { in++; ctxt->input->col++; }
|
||||
if (*in == 0xA) {
|
||||
do {
|
||||
ctxt->input->line++; ctxt->input->col = 1;
|
||||
in++;
|
||||
} while (*in == 0xA);
|
||||
goto get_more_space;
|
||||
}
|
||||
if (*in == '<') {
|
||||
nbchar = in - ctxt->input->cur;
|
||||
if (nbchar > 0) {
|
||||
const xmlChar *tmp = ctxt->input->cur;
|
||||
ctxt->input->cur = in;
|
||||
while (*in == 0x20) { in++; ctxt->input->col++; }
|
||||
if (*in == 0xA) {
|
||||
do {
|
||||
ctxt->input->line++; ctxt->input->col = 1;
|
||||
in++;
|
||||
} while (*in == 0xA);
|
||||
goto get_more_space;
|
||||
}
|
||||
if (*in == '<') {
|
||||
nbchar = in - ctxt->input->cur;
|
||||
if (nbchar > 0) {
|
||||
const xmlChar *tmp = ctxt->input->cur;
|
||||
ctxt->input->cur = in;
|
||||
|
||||
if ((ctxt->sax != NULL) &&
|
||||
(ctxt->sax->ignorableWhitespace !=
|
||||
ctxt->sax->characters)) {
|
||||
if (areBlanks(ctxt, tmp, nbchar, 1)) {
|
||||
if (ctxt->sax->ignorableWhitespace != NULL)
|
||||
ctxt->sax->ignorableWhitespace(ctxt->userData,
|
||||
tmp, nbchar);
|
||||
} else {
|
||||
if (ctxt->sax->characters != NULL)
|
||||
ctxt->sax->characters(ctxt->userData,
|
||||
tmp, nbchar);
|
||||
if (*ctxt->space == -1)
|
||||
*ctxt->space = -2;
|
||||
}
|
||||
} else if ((ctxt->sax != NULL) &&
|
||||
(ctxt->sax->characters != NULL)) {
|
||||
ctxt->sax->characters(ctxt->userData,
|
||||
tmp, nbchar);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ((ctxt->sax != NULL) &&
|
||||
(ctxt->sax->ignorableWhitespace !=
|
||||
ctxt->sax->characters)) {
|
||||
if (areBlanks(ctxt, tmp, nbchar, 1)) {
|
||||
if (ctxt->sax->ignorableWhitespace != NULL)
|
||||
ctxt->sax->ignorableWhitespace(ctxt->userData,
|
||||
tmp, nbchar);
|
||||
} else {
|
||||
if (ctxt->sax->characters != NULL)
|
||||
ctxt->sax->characters(ctxt->userData,
|
||||
tmp, nbchar);
|
||||
if (*ctxt->space == -1)
|
||||
*ctxt->space = -2;
|
||||
}
|
||||
} else if ((ctxt->sax != NULL) &&
|
||||
(ctxt->sax->characters != NULL)) {
|
||||
ctxt->sax->characters(ctxt->userData,
|
||||
tmp, nbchar);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
get_more:
|
||||
ccol = ctxt->input->col;
|
||||
while (test_char_data[*in]) {
|
||||
in++;
|
||||
ccol++;
|
||||
}
|
||||
ctxt->input->col = ccol;
|
||||
if (*in == 0xA) {
|
||||
do {
|
||||
ctxt->input->line++; ctxt->input->col = 1;
|
||||
in++;
|
||||
} while (*in == 0xA);
|
||||
goto get_more;
|
||||
}
|
||||
if (*in == ']') {
|
||||
if ((in[1] == ']') && (in[2] == '>')) {
|
||||
xmlFatalErr(ctxt, XML_ERR_MISPLACED_CDATA_END, NULL);
|
||||
ctxt->input->cur = in + 1;
|
||||
return;
|
||||
}
|
||||
in++;
|
||||
ctxt->input->col++;
|
||||
goto get_more;
|
||||
}
|
||||
nbchar = in - ctxt->input->cur;
|
||||
if (nbchar > 0) {
|
||||
if ((ctxt->sax != NULL) &&
|
||||
(ctxt->sax->ignorableWhitespace !=
|
||||
ctxt->sax->characters) &&
|
||||
(IS_BLANK_CH(*ctxt->input->cur))) {
|
||||
const xmlChar *tmp = ctxt->input->cur;
|
||||
ctxt->input->cur = in;
|
||||
ccol = ctxt->input->col;
|
||||
while (test_char_data[*in]) {
|
||||
in++;
|
||||
ccol++;
|
||||
}
|
||||
ctxt->input->col = ccol;
|
||||
if (*in == 0xA) {
|
||||
do {
|
||||
ctxt->input->line++; ctxt->input->col = 1;
|
||||
in++;
|
||||
} while (*in == 0xA);
|
||||
goto get_more;
|
||||
}
|
||||
if (*in == ']') {
|
||||
if ((in[1] == ']') && (in[2] == '>')) {
|
||||
xmlFatalErr(ctxt, XML_ERR_MISPLACED_CDATA_END, NULL);
|
||||
ctxt->input->cur = in + 1;
|
||||
return;
|
||||
}
|
||||
in++;
|
||||
ctxt->input->col++;
|
||||
goto get_more;
|
||||
}
|
||||
nbchar = in - ctxt->input->cur;
|
||||
if (nbchar > 0) {
|
||||
if ((ctxt->sax != NULL) &&
|
||||
(ctxt->sax->ignorableWhitespace !=
|
||||
ctxt->sax->characters) &&
|
||||
(IS_BLANK_CH(*ctxt->input->cur))) {
|
||||
const xmlChar *tmp = ctxt->input->cur;
|
||||
ctxt->input->cur = in;
|
||||
|
||||
if (areBlanks(ctxt, tmp, nbchar, 0)) {
|
||||
if (ctxt->sax->ignorableWhitespace != NULL)
|
||||
ctxt->sax->ignorableWhitespace(ctxt->userData,
|
||||
tmp, nbchar);
|
||||
} else {
|
||||
if (ctxt->sax->characters != NULL)
|
||||
ctxt->sax->characters(ctxt->userData,
|
||||
tmp, nbchar);
|
||||
if (*ctxt->space == -1)
|
||||
*ctxt->space = -2;
|
||||
}
|
||||
line = ctxt->input->line;
|
||||
col = ctxt->input->col;
|
||||
} else if (ctxt->sax != NULL) {
|
||||
if (ctxt->sax->characters != NULL)
|
||||
ctxt->sax->characters(ctxt->userData,
|
||||
ctxt->input->cur, nbchar);
|
||||
line = ctxt->input->line;
|
||||
col = ctxt->input->col;
|
||||
}
|
||||
/* something really bad happened in the SAX callback */
|
||||
if (ctxt->instate != XML_PARSER_CONTENT)
|
||||
return;
|
||||
}
|
||||
ctxt->input->cur = in;
|
||||
if (*in == 0xD) {
|
||||
in++;
|
||||
if (*in == 0xA) {
|
||||
ctxt->input->cur = in;
|
||||
in++;
|
||||
ctxt->input->line++; ctxt->input->col = 1;
|
||||
continue; /* while */
|
||||
}
|
||||
in--;
|
||||
}
|
||||
if (*in == '<') {
|
||||
return;
|
||||
}
|
||||
if (*in == '&') {
|
||||
return;
|
||||
}
|
||||
SHRINK;
|
||||
GROW;
|
||||
if (ctxt->instate == XML_PARSER_EOF)
|
||||
return;
|
||||
in = ctxt->input->cur;
|
||||
} while (((*in >= 0x20) && (*in <= 0x7F)) || (*in == 0x09) || (*in == 0x0a));
|
||||
nbchar = 0;
|
||||
}
|
||||
if (areBlanks(ctxt, tmp, nbchar, 0)) {
|
||||
if (ctxt->sax->ignorableWhitespace != NULL)
|
||||
ctxt->sax->ignorableWhitespace(ctxt->userData,
|
||||
tmp, nbchar);
|
||||
} else {
|
||||
if (ctxt->sax->characters != NULL)
|
||||
ctxt->sax->characters(ctxt->userData,
|
||||
tmp, nbchar);
|
||||
if (*ctxt->space == -1)
|
||||
*ctxt->space = -2;
|
||||
}
|
||||
line = ctxt->input->line;
|
||||
col = ctxt->input->col;
|
||||
} else if (ctxt->sax != NULL) {
|
||||
if (ctxt->sax->characters != NULL)
|
||||
ctxt->sax->characters(ctxt->userData,
|
||||
ctxt->input->cur, nbchar);
|
||||
line = ctxt->input->line;
|
||||
col = ctxt->input->col;
|
||||
}
|
||||
/* something really bad happened in the SAX callback */
|
||||
if (ctxt->instate != XML_PARSER_CONTENT)
|
||||
return;
|
||||
}
|
||||
ctxt->input->cur = in;
|
||||
if (*in == 0xD) {
|
||||
in++;
|
||||
if (*in == 0xA) {
|
||||
ctxt->input->cur = in;
|
||||
in++;
|
||||
ctxt->input->line++; ctxt->input->col = 1;
|
||||
continue; /* while */
|
||||
}
|
||||
in--;
|
||||
}
|
||||
if (*in == '<') {
|
||||
return;
|
||||
}
|
||||
if (*in == '&') {
|
||||
return;
|
||||
}
|
||||
SHRINK;
|
||||
GROW;
|
||||
if (ctxt->instate == XML_PARSER_EOF)
|
||||
return;
|
||||
in = ctxt->input->cur;
|
||||
} while (((*in >= 0x20) && (*in <= 0x7F)) ||
|
||||
(*in == 0x09) || (*in == 0x0a));
|
||||
ctxt->input->line = line;
|
||||
ctxt->input->col = col;
|
||||
xmlParseCharDataComplex(ctxt, cdata);
|
||||
xmlParseCharDataComplex(ctxt);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4594,7 +4592,7 @@ get_more:
|
||||
* of non-ASCII characters.
|
||||
*/
|
||||
static void
|
||||
xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata) {
|
||||
xmlParseCharDataComplex(xmlParserCtxtPtr ctxt) {
|
||||
xmlChar buf[XML_PARSER_BIG_BUFFER_SIZE + 5];
|
||||
int nbchar = 0;
|
||||
int cur, l;
|
||||
@ -4606,12 +4604,8 @@ xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cdata) {
|
||||
while ((cur != '<') && /* checked */
|
||||
(cur != '&') &&
|
||||
(IS_CHAR(cur))) /* test also done in xmlCurrentChar() */ {
|
||||
if ((cur == ']') && (NXT(1) == ']') &&
|
||||
(NXT(2) == '>')) {
|
||||
if (cdata) break;
|
||||
else {
|
||||
xmlFatalErr(ctxt, XML_ERR_MISPLACED_CDATA_END, NULL);
|
||||
}
|
||||
if ((cur == ']') && (NXT(1) == ']') && (NXT(2) == '>')) {
|
||||
xmlFatalErr(ctxt, XML_ERR_MISPLACED_CDATA_END, NULL);
|
||||
}
|
||||
COPY_BUF(l,buf,nbchar,cur);
|
||||
/* move current position before possible calling of ctxt->sax->characters */
|
||||
|
Loading…
x
Reference in New Issue
Block a user