Skip to content

Commit 78599f3

Browse files
fix: only use IndexedValidationError for indexed container types (#42)
1 parent 8b87737 commit 78599f3

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ version = "0.1.2"
1212
[workspace.dependencies]
1313
chrono = "0.4.42"
1414
email_address = { version = "0.2.9", default-features = false }
15-
fortifier = { path = "./packages/fortifier", version = "0.1.1" }
16-
fortifier-macros = { path = "./packages/fortifier-macros", version = "0.1.1" }
15+
fortifier = { path = "./packages/fortifier", version = "0.1.2" }
16+
fortifier-macros = { path = "./packages/fortifier-macros", version = "0.1.2" }
1717
indexmap = "2.12.0"
1818
phonenumber = "0.3.7"
1919
pretty_assertions = "1.4.1"

packages/fortifier-macros/src/validate/type.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@ const PRIMITIVE_AND_BUILT_IN_TYPES: [&str; 18] = [
99
"f32", "f64", "char", "str", "String",
1010
];
1111

12-
const INDEXED_CONTAINER_TYPES: [&str; 16] = [
12+
const CONTAINER_TYPES: [&str; 6] = [
1313
"Arc",
14+
"Option",
15+
"Rc",
16+
"std::option::Option",
17+
"std::rc::Rc",
18+
"std::sync::Arc",
19+
];
20+
21+
const INDEXED_CONTAINER_TYPES: [&str; 10] = [
1422
"BTreeSet",
1523
"HashSet",
1624
"LinkedList",
17-
"Option",
18-
"Rc",
1925
"Vec",
2026
"VecDeque",
2127
"std::collections::BTreeSet",
2228
"std::collections::HashSet",
2329
"std::collections::LinkedList",
2430
"std::collections::VecDeque",
25-
"std::option::Option",
26-
"std::rc::Rc",
27-
"std::sync::Arc",
2831
"std::vec::Vec",
2932
];
3033

@@ -74,6 +77,14 @@ fn should_validate_path(path: &Path) -> Option<KnownOrUnknown<TokenStream>> {
7477
let path_string = path_to_string(path);
7578
let path_string = path_string.as_str();
7679

80+
if CONTAINER_TYPES.contains(&path_string)
81+
&& let Some(segment) = path.segments.last()
82+
&& let PathArguments::AngleBracketed(arguments) = &segment.arguments
83+
&& let Some(argument) = arguments.args.first()
84+
{
85+
return should_validate_generic_argument(argument);
86+
}
87+
7788
if INDEXED_CONTAINER_TYPES.contains(&path_string)
7889
&& let Some(segment) = path.segments.last()
7990
&& let PathArguments::AngleBracketed(arguments) = &segment.arguments

0 commit comments

Comments
 (0)