You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2023/11/02 09:55:29 UTC
(avro) branch branch-1.11 updated: AVRO-3897: [Rust] Disallow invalid namespace in fully qualified name for Rust SDK (#2570)
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/branch-1.11 by this push:
new f9c5a2fb9 AVRO-3897: [Rust] Disallow invalid namespace in fully qualified name for Rust SDK (#2570)
f9c5a2fb9 is described below
commit f9c5a2fb946e1bc867e60fbd9152d78dbfd235e4
Author: Kousuke Saruta <sa...@apache.org>
AuthorDate: Thu Nov 2 18:55:09 2023 +0900
AVRO-3897: [Rust] Disallow invalid namespace in fully qualified name for Rust SDK (#2570)
* AVRO-3897: [Rust] Disallow invalid namespace in fully qualified name for Rust SDK
* AVRO-3897: [Rust] Cleanup the test code
Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
* AVRO-3897: [Rust] Add a test case showing that name[space]s could be only underscores
Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
---------
Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
Co-authored-by: Martin Tzvetanov Grigorov <mg...@apache.org>
(cherry picked from commit e8f48a98bcd3b2c3772a604847ce57eb9903a72c)
---
lang/rust/avro/src/schema.rs | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/lang/rust/avro/src/schema.rs b/lang/rust/avro/src/schema.rs
index 13e36b550..d91e51f2d 100644
--- a/lang/rust/avro/src/schema.rs
+++ b/lang/rust/avro/src/schema.rs
@@ -42,7 +42,7 @@ lazy_static! {
// An optional namespace (with optional dots) followed by a name without any dots in it.
static ref SCHEMA_NAME_R: Regex =
- Regex::new(r"^((?P<namespace>([A-Za-z_][A-Za-z0-9_\.]*)*)\.)?(?P<name>[A-Za-z_][A-Za-z0-9_]*)$").unwrap();
+ Regex::new(r"^((?P<namespace>([A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*)?)\.)?(?P<name>[A-Za-z_][A-Za-z0-9_]*)$").unwrap();
static ref FIELD_NAME_R: Regex = Regex::new(r"^[A-Za-z_][A-Za-z0-9_]*$").unwrap();
@@ -6154,4 +6154,37 @@ mod tests {
Ok(())
}
+
+ #[test]
+ fn test_avro_3897_disallow_invalid_namespaces_in_fully_qualified_name() -> TestResult {
+ let full_name = "ns.0.record1";
+ let name = Name::new(full_name);
+ assert!(name.is_err());
+ let expected =
+ Error::InvalidSchemaName(full_name.to_string(), SCHEMA_NAME_R.as_str()).to_string();
+ let err = name.map_err(|e| e.to_string()).err().unwrap();
+ assert_eq!(expected, err);
+
+ let full_name = "ns..record1";
+ let name = Name::new(full_name);
+ assert!(name.is_err());
+ let expected =
+ Error::InvalidSchemaName(full_name.to_string(), SCHEMA_NAME_R.as_str()).to_string();
+ let err = name.map_err(|e| e.to_string()).err().unwrap();
+ assert_eq!(expected, err);
+
+ Ok(())
+ }
+
+ /// A test cases showing that names and namespaces can be constructed
+ /// entirely by underscores.
+ #[test]
+ fn test_avro_3897_funny_valid_names_and_namespaces() -> TestResult {
+ for funny_name in ["_", "_._", "__._", "_.__", "_._._"] {
+ let name = Name::new(funny_name);
+ assert!(name.is_ok());
+ }
+
+ Ok(())
+ }
}