MDEV-30704: JSON_SCHEMA_VALID: multipleOf must be greater than zero
Analysis: multipleOf must be strictly greater then 0. However the implementation only disallowed values strcitly less than 0 Fix: check if value is less than or equal to 0 instead of less than 0 and return true. Also fixed the incorrect return value for some other keywords.
This commit is contained in:
parent
dffd1679ba
commit
2c4c7c8b02
@ -4605,4 +4605,33 @@ SET @schema = '{
|
||||
}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
ERROR HY000: Invalid value for keyword enum
|
||||
#
|
||||
# MDEV-30704: JSON_SCHEMA_VALID: multipleOf must be greater than zero
|
||||
#
|
||||
SET @schema = '{
|
||||
"multipleOf": 0
|
||||
}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
ERROR HY000: Invalid value for keyword multipleOf
|
||||
SET @schema= '{ "maxLength" : -3}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
ERROR HY000: Invalid value for keyword maxLength
|
||||
SET @schema= '{ "minLength" : -3}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
ERROR HY000: Invalid value for keyword minLength
|
||||
SET @schema= '{ "maxProperties" : -3}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
ERROR HY000: Invalid value for keyword maxProperties
|
||||
SET @schema= '{ "minProperties" : -3}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
ERROR HY000: Invalid value for keyword minProperties
|
||||
SET @schema= '{ "maxItems" : -3}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
ERROR HY000: Invalid value for keyword maxItems
|
||||
SET @schema= '{ "minItems" : -3}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
ERROR HY000: Invalid value for keyword maxLength
|
||||
SET @schema= '{ "items" : ["str1"]}';
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '[]');
|
||||
ERROR HY000: Invalid value for keyword items
|
||||
# End of 11.1 test
|
||||
|
@ -3494,4 +3494,43 @@ SET @schema = '{
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-30704: JSON_SCHEMA_VALID: multipleOf must be greater than zero
|
||||
--echo #
|
||||
|
||||
SET @schema = '{
|
||||
"multipleOf": 0
|
||||
}';
|
||||
--error ER_JSON_INVALID_VALUE_FOR_KEYWORD
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
|
||||
SET @schema= '{ "maxLength" : -3}';
|
||||
--error ER_JSON_INVALID_VALUE_FOR_KEYWORD
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
|
||||
SET @schema= '{ "minLength" : -3}';
|
||||
--error ER_JSON_INVALID_VALUE_FOR_KEYWORD
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
|
||||
SET @schema= '{ "maxProperties" : -3}';
|
||||
--error ER_JSON_INVALID_VALUE_FOR_KEYWORD
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
|
||||
SET @schema= '{ "minProperties" : -3}';
|
||||
--error ER_JSON_INVALID_VALUE_FOR_KEYWORD
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
|
||||
SET @schema= '{ "maxItems" : -3}';
|
||||
--error ER_JSON_INVALID_VALUE_FOR_KEYWORD
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
|
||||
SET @schema= '{ "minItems" : -3}';
|
||||
--error ER_JSON_INVALID_VALUE_FOR_KEYWORD
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '2');
|
||||
|
||||
SET @schema= '{ "items" : ["str1"]}';
|
||||
--error ER_JSON_INVALID_VALUE_FOR_KEYWORD
|
||||
SELECT JSON_SCHEMA_VALID(@schema, '[]');
|
||||
|
||||
|
||||
--echo # End of 11.1 test
|
||||
|
@ -774,7 +774,7 @@ bool Json_schema_multiple_of::validate(const json_engine_t *je,
|
||||
|
||||
double val= je->s.cs->strntod((char *) je->value,
|
||||
je->value_len, &end, &err);
|
||||
double temp= val / this->value;
|
||||
double temp= val / multiple_of;
|
||||
bool res= (temp - (long long int)temp) == 0;
|
||||
|
||||
return !res;
|
||||
@ -797,12 +797,12 @@ bool Json_schema_multiple_of::handle_keyword(THD *thd, json_engine_t *je,
|
||||
|
||||
double val= je->s.cs->strntod((char *) je->value,
|
||||
je->value_len, &end, &err);
|
||||
if (val < 0)
|
||||
if (val <= 0)
|
||||
{
|
||||
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "multipleOf");
|
||||
return true;
|
||||
}
|
||||
value= val;
|
||||
multiple_of= val;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -834,8 +834,11 @@ bool Json_schema_max_len::handle_keyword(THD *thd, json_engine_t *je,
|
||||
double val= je->s.cs->strntod((char *) je->value,
|
||||
je->value_len, &end, &err);
|
||||
if (val < 0)
|
||||
{
|
||||
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "maxLength");
|
||||
value= val;
|
||||
return true;
|
||||
}
|
||||
value= (int)val;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -869,9 +872,17 @@ bool Json_schema_min_len::handle_keyword(THD *thd, json_engine_t *je,
|
||||
if (val < 0)
|
||||
{
|
||||
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "minLength");
|
||||
<<<<<<< HEAD
|
||||
return true;
|
||||
}
|
||||
value= val;
|
||||
||||||| parent of 203f63d7bf1... MDEV-30704: JSON_SCHEMA_VALID: multipleOf must be greater than zero
|
||||
value= val;
|
||||
=======
|
||||
return true;
|
||||
}
|
||||
value= (int)val;
|
||||
>>>>>>> 203f63d7bf1... MDEV-30704: JSON_SCHEMA_VALID: multipleOf must be greater than zero
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -982,8 +993,11 @@ bool Json_schema_max_items::handle_keyword(THD *thd, json_engine_t *je,
|
||||
double val= je->s.cs->strntod((char *) je->value,
|
||||
je->value_len, &end, &err);
|
||||
if (val < 0)
|
||||
{
|
||||
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "maxItems");
|
||||
value= val;
|
||||
return true;
|
||||
}
|
||||
value= (int)val;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1037,7 +1051,7 @@ bool Json_schema_min_items::handle_keyword(THD *thd, json_engine_t *je,
|
||||
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "maxLength");
|
||||
return true;
|
||||
}
|
||||
value= val;
|
||||
value= (int)val;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1279,9 +1293,14 @@ bool Json_schema_prefix_items::handle_keyword(THD *thd, json_engine_t *je,
|
||||
char *begin, *end;
|
||||
int len;
|
||||
|
||||
if (json_read_value(je))
|
||||
return true;
|
||||
begin= (char*)je->value;
|
||||
if (json_read_value(je))
|
||||
return true;
|
||||
if (je->value_type != JSON_VALUE_OBJECT)
|
||||
{
|
||||
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "items");
|
||||
return true;
|
||||
}
|
||||
begin= (char*)je->value;
|
||||
|
||||
if (json_skip_level(je))
|
||||
return true;
|
||||
@ -1452,7 +1471,7 @@ bool Json_schema_max_prop::handle_keyword(THD *thd, json_engine_t *je,
|
||||
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "maxProperties");
|
||||
return true;
|
||||
}
|
||||
value= val;
|
||||
value= (int)val;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1511,7 +1530,7 @@ bool Json_schema_min_prop::handle_keyword(THD *thd, json_engine_t *je,
|
||||
my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "minProperties");
|
||||
return true;
|
||||
}
|
||||
value= val;
|
||||
value= (int)val;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -227,6 +227,8 @@ class Json_schema_minimum : public Json_schema_keyword
|
||||
|
||||
class Json_schema_multiple_of : public Json_schema_keyword
|
||||
{
|
||||
private:
|
||||
double multiple_of;
|
||||
public:
|
||||
bool validate(const json_engine_t *je, const uchar *k_start= NULL,
|
||||
const uchar *k_end= NULL) override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user