File tree Expand file tree Collapse file tree 2 files changed +38
-5
lines changed Expand file tree Collapse file tree 2 files changed +38
-5
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ pub fn build_regex_from_schema(json: &str, whitespace_pattern: Option<&str>) ->
14
14
to_regex ( & json_value, whitespace_pattern)
15
15
}
16
16
17
- #[ allow( clippy:: wrong_self_convention) ]
18
17
pub fn to_regex ( json : & Value , whitespace_pattern : Option < & str > ) -> Result < String > {
19
18
let mut parser = parsing:: Parser :: new ( json) ;
20
19
if let Some ( pattern) = whitespace_pattern {
@@ -1061,4 +1060,42 @@ mod tests {
1061
1060
regex,
1062
1061
) ;
1063
1062
}
1063
+
1064
+ #[ test]
1065
+ fn triple_recursion_doesnt_fail ( ) {
1066
+ let json = r##"
1067
+ {
1068
+ "definitions": {
1069
+ "typeA": {
1070
+ "type": "object",
1071
+ "properties": {
1072
+ "name": { "type": "string" },
1073
+ "child": { "$ref": "#/definitions/typeB" }
1074
+ },
1075
+ "required": ["name"]
1076
+ },
1077
+ "typeB": {
1078
+ "type": "object",
1079
+ "properties": {
1080
+ "value": { "type": "number" },
1081
+ "next": { "$ref": "#/definitions/typeC" }
1082
+ },
1083
+ "required": ["value"]
1084
+ },
1085
+ "typeC": {
1086
+ "type": "object",
1087
+ "properties": {
1088
+ "flag": { "type": "boolean" },
1089
+ "parent": { "$ref": "#/definitions/typeA" }
1090
+ },
1091
+ "required": ["flag"]
1092
+ }
1093
+ },
1094
+ "$ref": "#/definitions/typeA"
1095
+ }"## ;
1096
+
1097
+ let json_value: Value = serde_json:: from_str ( json) . expect ( "Can't parse json" ) ;
1098
+ let regex = to_regex ( & json_value, None ) ;
1099
+ assert ! ( regex. is_ok( ) , "{:?}" , regex) ;
1100
+ }
1064
1101
}
Original file line number Diff line number Diff line change 1
- use std:: collections:: HashSet ;
2
1
use std:: num:: NonZeroU64 ;
3
2
4
3
use regex:: escape;
@@ -13,7 +12,6 @@ type Result<T> = std::result::Result<T, JsonSchemaParserError>;
13
12
pub ( crate ) struct Parser < ' a > {
14
13
root : & ' a Value ,
15
14
whitespace_pattern : & ' a str ,
16
- visited : HashSet < usize > ,
17
15
recursion_depth : usize ,
18
16
max_recursion_depth : usize ,
19
17
}
@@ -30,7 +28,6 @@ impl<'a> Parser<'a> {
30
28
Self {
31
29
root,
32
30
whitespace_pattern : types:: WHITESPACE ,
33
- visited : HashSet :: new ( ) ,
34
31
recursion_depth : 0 ,
35
32
max_recursion_depth : 3 ,
36
33
}
@@ -280,7 +277,6 @@ impl<'a> Parser<'a> {
280
277
}
281
278
282
279
fn parse_ref ( & mut self , obj : & serde_json:: Map < String , Value > ) -> Result < String > {
283
- self . visited . insert ( obj as * const _ as usize ) ;
284
280
if self . recursion_depth > self . max_recursion_depth {
285
281
return Err ( JsonSchemaParserError :: RefRecursionLimitReached (
286
282
self . max_recursion_depth ,
You can’t perform that action at this time.
0 commit comments