mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-30995: JSON_SCHEMA_VALID is not validating case sensitive when using
regex Analysis: When initializing Regexp_processor_pcre object, we set the PCRE2_CASELESS flag which is responsible for case insensitive comparison. Fix: Unset the flag after initializing.
This commit is contained in:
@ -4496,4 +4496,43 @@ ERROR HY000: Invalid value for keyword minContains
|
|||||||
SET @schema_required='{"type":"object","required":[1,"str1", "str1"]}';
|
SET @schema_required='{"type":"object","required":[1,"str1", "str1"]}';
|
||||||
SELECT JSON_SCHEMA_VALID(@schema_required,'{"num1":1, "str1":"abc", "arr1":[1,2,3]}');
|
SELECT JSON_SCHEMA_VALID(@schema_required,'{"num1":1, "str1":"abc", "arr1":[1,2,3]}');
|
||||||
ERROR HY000: Invalid value for keyword required
|
ERROR HY000: Invalid value for keyword required
|
||||||
|
#
|
||||||
|
# MDEV-30995: JSON_SCHEMA_VALID is not validating case sensitive when using regex
|
||||||
|
#
|
||||||
|
SET @schema_pattern='{
|
||||||
|
"type": "string",
|
||||||
|
"pattern": "[A-Z]"
|
||||||
|
}';
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_pattern, '"a"');
|
||||||
|
JSON_SCHEMA_VALID(@schema_pattern, '"a"')
|
||||||
|
0
|
||||||
|
SET @schema_property_names='{
|
||||||
|
"PropertyNames":{
|
||||||
|
"pattern": "^I_"
|
||||||
|
}
|
||||||
|
}';
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_property_names, '{"I_num":4}');
|
||||||
|
JSON_SCHEMA_VALID(@schema_property_names, '{"I_num":4}')
|
||||||
|
1
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_property_names, '{"i_num":4}');
|
||||||
|
JSON_SCHEMA_VALID(@schema_property_names, '{"i_num":4}')
|
||||||
|
0
|
||||||
|
SET @schema_pattern_properties= '{
|
||||||
|
"patternProperties": {
|
||||||
|
"^I_": {"type":"number", "maximum":100},
|
||||||
|
"^S_" : {"type":"string", "maxLength":4}
|
||||||
|
}
|
||||||
|
}';
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 50}');
|
||||||
|
JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 50}')
|
||||||
|
1
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 150}');
|
||||||
|
JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 150}')
|
||||||
|
0
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 50}');
|
||||||
|
JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 50}')
|
||||||
|
1
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 150}');
|
||||||
|
JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 150}')
|
||||||
|
1
|
||||||
# End of 11.1 test
|
# End of 11.1 test
|
||||||
|
@ -3399,4 +3399,33 @@ SET @schema_required='{"type":"object","required":[1,"str1", "str1"]}';
|
|||||||
SELECT JSON_SCHEMA_VALID(@schema_required,'{"num1":1, "str1":"abc", "arr1":[1,2,3]}');
|
SELECT JSON_SCHEMA_VALID(@schema_required,'{"num1":1, "str1":"abc", "arr1":[1,2,3]}');
|
||||||
|
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-30995: JSON_SCHEMA_VALID is not validating case sensitive when using regex
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
SET @schema_pattern='{
|
||||||
|
"type": "string",
|
||||||
|
"pattern": "[A-Z]"
|
||||||
|
}';
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_pattern, '"a"');
|
||||||
|
|
||||||
|
SET @schema_property_names='{
|
||||||
|
"PropertyNames":{
|
||||||
|
"pattern": "^I_"
|
||||||
|
}
|
||||||
|
}';
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_property_names, '{"I_num":4}');
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_property_names, '{"i_num":4}');
|
||||||
|
|
||||||
|
SET @schema_pattern_properties= '{
|
||||||
|
"patternProperties": {
|
||||||
|
"^I_": {"type":"number", "maximum":100},
|
||||||
|
"^S_" : {"type":"string", "maxLength":4}
|
||||||
|
}
|
||||||
|
}';
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 50}');
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 150}');
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 50}');
|
||||||
|
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 150}');
|
||||||
|
|
||||||
--echo # End of 11.1 test
|
--echo # End of 11.1 test
|
||||||
|
@ -3051,6 +3051,7 @@ public:
|
|||||||
bool is_const() const { return m_is_const; }
|
bool is_const() const { return m_is_const; }
|
||||||
void set_const(bool arg) { m_is_const= arg; }
|
void set_const(bool arg) { m_is_const= arg; }
|
||||||
CHARSET_INFO * library_charset() const { return m_library_charset; }
|
CHARSET_INFO * library_charset() const { return m_library_charset; }
|
||||||
|
void unset_flag(int flag) { m_library_flags&= ~flag; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <m_string.h>
|
#include <m_string.h>
|
||||||
#include "json_schema.h"
|
#include "json_schema.h"
|
||||||
#include "json_schema_helper.h"
|
#include "json_schema_helper.h"
|
||||||
|
#include "pcre2.h"
|
||||||
static HASH all_keywords_hash;
|
static HASH all_keywords_hash;
|
||||||
|
|
||||||
static Json_schema_keyword *create_json_schema_keyword(THD *thd)
|
static Json_schema_keyword *create_json_schema_keyword(THD *thd)
|
||||||
@ -917,6 +917,7 @@ bool Json_schema_pattern::handle_keyword(THD *thd, json_engine_t *je,
|
|||||||
str= (Item_string*)current_thd->make_string_literal((const char*)"",
|
str= (Item_string*)current_thd->make_string_literal((const char*)"",
|
||||||
0, repertoire);
|
0, repertoire);
|
||||||
re.init(je->s.cs, 0);
|
re.init(je->s.cs, 0);
|
||||||
|
re.unset_flag(PCRE2_CASELESS);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2219,7 +2220,7 @@ bool Json_schema_pattern_properties::handle_keyword(THD *thd,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
str= (Item_string*)current_thd->make_string_literal((const char*)"",
|
str= (Item_string*)thd->make_string_literal((const char*)"",
|
||||||
0,
|
0,
|
||||||
my_charset_repertoire(je->s.cs));
|
my_charset_repertoire(je->s.cs));
|
||||||
|
|
||||||
@ -2250,6 +2251,7 @@ bool Json_schema_pattern_properties::handle_keyword(THD *thd,
|
|||||||
(size_t)(k_end-k_start),
|
(size_t)(k_end-k_start),
|
||||||
repertoire);
|
repertoire);
|
||||||
curr_pattern_to_property->re.init(je->s.cs, 0);
|
curr_pattern_to_property->re.init(je->s.cs, 0);
|
||||||
|
curr_pattern_to_property->re.unset_flag(PCRE2_CASELESS);
|
||||||
curr_pattern_to_property->curr_schema=
|
curr_pattern_to_property->curr_schema=
|
||||||
new (thd->mem_root) List<Json_schema_keyword>;
|
new (thd->mem_root) List<Json_schema_keyword>;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user