aconfig: package fields must contain at least one dot char
Introduce a new requirement on package fields: a package must contain at least one dot character. Bug: 289336036 Test: atest aconfig.test Change-Id: Idadcd2a76783a484cc5c6d6e94778c0248fa475f
This commit is contained in:
parent
c0d618c3a4
commit
19776d19e6
2 changed files with 10 additions and 5 deletions
|
@ -32,6 +32,9 @@ pub fn is_valid_name_ident(s: &str) -> bool {
|
|||
}
|
||||
|
||||
pub fn is_valid_package_ident(s: &str) -> bool {
|
||||
if !s.contains('.') {
|
||||
return false;
|
||||
}
|
||||
s.split('.').all(is_valid_name_ident)
|
||||
}
|
||||
|
||||
|
@ -61,11 +64,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_is_valid_package_ident() {
|
||||
assert!(is_valid_package_ident("foo"));
|
||||
assert!(is_valid_package_ident("foo_bar_123"));
|
||||
assert!(is_valid_package_ident("foo.bar"));
|
||||
assert!(is_valid_package_ident("foo.bar_baz"));
|
||||
assert!(is_valid_package_ident("foo.bar.a123"));
|
||||
|
||||
assert!(!is_valid_package_ident("foo_bar_123"));
|
||||
assert!(!is_valid_package_ident("foo"));
|
||||
assert!(!is_valid_package_ident("foo._bar"));
|
||||
assert!(!is_valid_package_ident(""));
|
||||
assert!(!is_valid_package_ident("123_foo"));
|
||||
|
@ -75,6 +79,7 @@ mod tests {
|
|||
assert!(!is_valid_package_ident(".foo.bar"));
|
||||
assert!(!is_valid_package_ident("foo.bar."));
|
||||
assert!(!is_valid_package_ident("."));
|
||||
assert!(!is_valid_package_ident(".."));
|
||||
assert!(!is_valid_package_ident("foo..bar"));
|
||||
assert!(!is_valid_package_ident("foo.__bar"));
|
||||
}
|
||||
|
|
|
@ -549,7 +549,7 @@ parsed_flag {
|
|||
// bad input: parsed_flag not sorted by package
|
||||
let text_proto = r#"
|
||||
parsed_flag {
|
||||
package: "bbb"
|
||||
package: "bbb.bbb"
|
||||
name: "first"
|
||||
namespace: "first_ns"
|
||||
description: "This is the description of the first flag."
|
||||
|
@ -562,7 +562,7 @@ parsed_flag {
|
|||
}
|
||||
}
|
||||
parsed_flag {
|
||||
package: "aaa"
|
||||
package: "aaa.aaa"
|
||||
name: "second"
|
||||
namespace: "second_ns"
|
||||
description: "This is the description of the second flag."
|
||||
|
@ -578,7 +578,7 @@ parsed_flag {
|
|||
let error = try_from_binary_proto_from_text_proto(text_proto).unwrap_err();
|
||||
assert_eq!(
|
||||
format!("{:?}", error),
|
||||
"bad parsed flags: not sorted: bbb.first comes before aaa.second"
|
||||
"bad parsed flags: not sorted: bbb.bbb.first comes before aaa.aaa.second"
|
||||
);
|
||||
|
||||
// bad input: parsed_flag not sorted by name
|
||||
|
|
Loading…
Reference in a new issue