1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

MDEV-40008 sql_error.cc:357: void Diagnostics_area::set_ok_status after CHECK (XMLISVALID..

Two things fixed. Firstly the error returns proper ::fix_length_and_dec
result.
Then the XML Schema allows elements with no type specified. The element
should has no value at all or only whitespaces as a value.
This commit is contained in:
Alexey (Holyfoot) Botchkov
2026-07-08 10:46:34 +03:00
committed by Alexey Botchkov
parent 2906844980
commit b73361c170
3 changed files with 63 additions and 3 deletions

View File

@@ -825,6 +825,29 @@ static uint xml_num_state_types[NS_NUM_STATES]=
};
class XMLSchema_empty_builtin_type: public XMLSchema_builtin_type
{
public:
bool valid_value(const char *value, size_t len) override
{
/* Only allow some whitespaces as a value. */
size_t pos= 0;
while (len > pos)
{
unsigned int c= ((uchar *) value)[pos++];
if (c >= array_elements(xml_num_chr_map))
return 0;
if (xml_num_chr_map[c] != N_SPC)
return 0;
}
return 1;
}
};
class XMLSchema_num_builtin_type: public XMLSchema_builtin_type
{
public:
@@ -3011,8 +3034,17 @@ bool XMLSchema_element_global::enter_tag(MY_XML_VALIDATION_DATA *st,
bool XMLSchema_element_global::resolve_type(
MY_XML_VALIDATION_DATA *st, LEX_CSTRING *bad_type)
{
m_type= st->schema->find_type_by_name(
st, m_atr_type.m_val, m_atr_type.m_val_len);
if (!m_atr_type.is_set())
{
XMLSchema_builtin_type *builtin_type;
builtin_type= new(st->mem_root) XMLSchema_empty_builtin_type();
m_type= new(st->mem_root) XMLSchema_simple_builtin_type(builtin_type);
}
else
{
m_type= st->schema->find_type_by_name(
st, m_atr_type.m_val, m_atr_type.m_val_len);
}
if (m_type)
return MY_XML_OK;
@@ -3407,7 +3439,7 @@ static int schema_parse(THD *thd, const String *xml,
exit:
my_xml_parser_free(&p);
return 0;
return rc;
}

View File

@@ -1986,3 +1986,13 @@ select XMLISVALID(@xml, @schema);
XMLISVALID(@xml, @schema)
1
# End of 11.8 tests
CREATE TABLE t (x XMLTYPE,CHECK (XMLISVALID(x, '<xs:scema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="a"/></xs:schema>')));
ERROR HY000: Incorrect XML value: 'XML Schema parse error at line 1 pos 88: '</xs:schema>' unexpected ('</xs:scema>' wanted)'
CREATE TABLE t (x XMLTYPE,CHECK (
XMLISVALID(x, '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="a"/></xs:schema>')));
INSERT INTO t VALUES ('<a />');
INSERT INTO t VALUES ('<a> </a>');
INSERT INTO t VALUES ('<a> </a>');
INSERT INTO t VALUES ('<a>Text</a>');
ERROR 23000: CONSTRAINT `CONSTRAINT_1` failed for `test`.`t`
DROP TABLE t;

View File

@@ -2079,3 +2079,21 @@ select XMLISVALID(@xml, @schema);
--echo # End of 11.8 tests
#
# MDEV-40008 sql_error.cc:357: void Diagnostics_area::set_ok_status after CHECK (XMLISVALID
#
--error ER_WRONG_VALUE
CREATE TABLE t (x XMLTYPE,CHECK (XMLISVALID(x, '<xs:scema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="a"/></xs:schema>')));
CREATE TABLE t (x XMLTYPE,CHECK (
XMLISVALID(x, '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="a"/></xs:schema>')));
INSERT INTO t VALUES ('<a />');
INSERT INTO t VALUES ('<a> </a>');
INSERT INTO t VALUES ('<a> </a>');
--error ER_CONSTRAINT_FAILED
INSERT INTO t VALUES ('<a>Text</a>');
DROP TABLE t;