Skip to content

Commit ee41fa3

Browse files
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.
1 parent 8939e21 commit ee41fa3

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

mysql-test/main/func_json.result

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4496,4 +4496,43 @@ ERROR HY000: Invalid value for keyword minContains
44964496
SET @schema_required='{"type":"object","required":[1,"str1", "str1"]}';
44974497
SELECT JSON_SCHEMA_VALID(@schema_required,'{"num1":1, "str1":"abc", "arr1":[1,2,3]}');
44984498
ERROR HY000: Invalid value for keyword required
4499+
#
4500+
# MDEV-30995: JSON_SCHEMA_VALID is not validating case sensitive when using regex
4501+
#
4502+
SET @schema_pattern='{
4503+
"type": "string",
4504+
"pattern": "[A-Z]"
4505+
}';
4506+
SELECT JSON_SCHEMA_VALID(@schema_pattern, '"a"');
4507+
JSON_SCHEMA_VALID(@schema_pattern, '"a"')
4508+
0
4509+
SET @schema_property_names='{
4510+
"PropertyNames":{
4511+
"pattern": "^I_"
4512+
}
4513+
}';
4514+
SELECT JSON_SCHEMA_VALID(@schema_property_names, '{"I_num":4}');
4515+
JSON_SCHEMA_VALID(@schema_property_names, '{"I_num":4}')
4516+
1
4517+
SELECT JSON_SCHEMA_VALID(@schema_property_names, '{"i_num":4}');
4518+
JSON_SCHEMA_VALID(@schema_property_names, '{"i_num":4}')
4519+
0
4520+
SET @schema_pattern_properties= '{
4521+
"patternProperties": {
4522+
"^I_": {"type":"number", "maximum":100},
4523+
"^S_" : {"type":"string", "maxLength":4}
4524+
}
4525+
}';
4526+
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 50}');
4527+
JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 50}')
4528+
1
4529+
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 150}');
4530+
JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 150}')
4531+
0
4532+
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 50}');
4533+
JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 50}')
4534+
1
4535+
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 150}');
4536+
JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 150}')
4537+
1
44994538
# End of 11.1 test

mysql-test/main/func_json.test

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,4 +3399,33 @@ SET @schema_required='{"type":"object","required":[1,"str1", "str1"]}';
33993399
SELECT JSON_SCHEMA_VALID(@schema_required,'{"num1":1, "str1":"abc", "arr1":[1,2,3]}');
34003400

34013401

3402+
--echo #
3403+
--echo # MDEV-30995: JSON_SCHEMA_VALID is not validating case sensitive when using regex
3404+
--echo #
3405+
3406+
SET @schema_pattern='{
3407+
"type": "string",
3408+
"pattern": "[A-Z]"
3409+
}';
3410+
SELECT JSON_SCHEMA_VALID(@schema_pattern, '"a"');
3411+
3412+
SET @schema_property_names='{
3413+
"PropertyNames":{
3414+
"pattern": "^I_"
3415+
}
3416+
}';
3417+
SELECT JSON_SCHEMA_VALID(@schema_property_names, '{"I_num":4}');
3418+
SELECT JSON_SCHEMA_VALID(@schema_property_names, '{"i_num":4}');
3419+
3420+
SET @schema_pattern_properties= '{
3421+
"patternProperties": {
3422+
"^I_": {"type":"number", "maximum":100},
3423+
"^S_" : {"type":"string", "maxLength":4}
3424+
}
3425+
}';
3426+
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 50}');
3427+
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"I_": 150}');
3428+
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 50}');
3429+
SELECT JSON_SCHEMA_VALID(@schema_pattern_properties, '{"i_": 150}');
3430+
34023431
--echo # End of 11.1 test

sql/item_cmpfunc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,6 +3051,7 @@ class Regexp_processor_pcre
30513051
bool is_const() const { return m_is_const; }
30523052
void set_const(bool arg) { m_is_const= arg; }
30533053
CHARSET_INFO * library_charset() const { return m_library_charset; }
3054+
void unset_flag(int flag) { m_library_flags&= ~flag; }
30543055
};
30553056

30563057

sql/json_schema.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <m_string.h>
2121
#include "json_schema.h"
2222
#include "json_schema_helper.h"
23-
23+
#include "pcre2.h"
2424
static HASH all_keywords_hash;
2525

2626
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,
917917
str= (Item_string*)current_thd->make_string_literal((const char*)"",
918918
0, repertoire);
919919
re.init(je->s.cs, 0);
920+
re.unset_flag(PCRE2_CASELESS);
920921

921922
return false;
922923
}
@@ -2219,7 +2220,7 @@ bool Json_schema_pattern_properties::handle_keyword(THD *thd,
22192220
return true;
22202221
}
22212222

2222-
str= (Item_string*)current_thd->make_string_literal((const char*)"",
2223+
str= (Item_string*)thd->make_string_literal((const char*)"",
22232224
0,
22242225
my_charset_repertoire(je->s.cs));
22252226

@@ -2250,6 +2251,7 @@ bool Json_schema_pattern_properties::handle_keyword(THD *thd,
22502251
(size_t)(k_end-k_start),
22512252
repertoire);
22522253
curr_pattern_to_property->re.init(je->s.cs, 0);
2254+
curr_pattern_to_property->re.unset_flag(PCRE2_CASELESS);
22532255
curr_pattern_to_property->curr_schema=
22542256
new (thd->mem_root) List<Json_schema_keyword>;
22552257

0 commit comments

Comments
 (0)