summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRucha Deodhar <rucha.deodhar@mariadb.com>2023-04-04 13:35:02 +0530
committerRucha Deodhar <rucha.deodhar@mariadb.com>2023-04-26 11:00:08 +0530
commitee41fa38fc3b393e0e7b73bed098274248b8492d (patch)
treee173eccf91f6886ef7e7da82ad9378bc59e06e91
parent8939e21dc53bcb076da6991fb5b6114abfb3ee37 (diff)
downloadmariadb-git-ee41fa38fc3b393e0e7b73bed098274248b8492d.tar.gz
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.
-rw-r--r--mysql-test/main/func_json.result39
-rw-r--r--mysql-test/main/func_json.test29
-rw-r--r--sql/item_cmpfunc.h1
-rw-r--r--sql/json_schema.cc6
4 files changed, 73 insertions, 2 deletions
diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result
index dddfcf8f1cd..29939d69e83 100644
--- a/mysql-test/main/func_json.result
+++ b/mysql-test/main/func_json.result
@@ -4496,4 +4496,43 @@ ERROR HY000: Invalid value for keyword minContains
SET @schema_required='{"type":"object","required":[1,"str1", "str1"]}';
SELECT JSON_SCHEMA_VALID(@schema_required,'{"num1":1, "str1":"abc", "arr1":[1,2,3]}');
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
diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test
index 706a01d4528..5517dcfa6c8 100644
--- a/mysql-test/main/func_json.test
+++ b/mysql-test/main/func_json.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]}');
+--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
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index 7f808580470..d34bad95a57 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -3051,6 +3051,7 @@ public:
bool is_const() const { return m_is_const; }
void set_const(bool arg) { m_is_const= arg; }
CHARSET_INFO * library_charset() const { return m_library_charset; }
+ void unset_flag(int flag) { m_library_flags&= ~flag; }
};
diff --git a/sql/json_schema.cc b/sql/json_schema.cc
index 2279bb59f9a..cdfe91a206d 100644
--- a/sql/json_schema.cc
+++ b/sql/json_schema.cc
@@ -20,7 +20,7 @@
#include <m_string.h>
#include "json_schema.h"
#include "json_schema_helper.h"
-
+#include "pcre2.h"
static HASH all_keywords_hash;
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*)"",
0, repertoire);
re.init(je->s.cs, 0);
+ re.unset_flag(PCRE2_CASELESS);
return false;
}
@@ -2219,7 +2220,7 @@ bool Json_schema_pattern_properties::handle_keyword(THD *thd,
return true;
}
- str= (Item_string*)current_thd->make_string_literal((const char*)"",
+ str= (Item_string*)thd->make_string_literal((const char*)"",
0,
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),
repertoire);
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=
new (thd->mem_root) List<Json_schema_keyword>;