Skip to content

Commit 6ce466a

Browse files
committed
fix: simplify parse_inner_type and make it more strict
It now ensures that the brackets and quotes are balanced, and no longer consumes a trailing closing bracket if there's no matching opening bracket.
1 parent fa8499b commit 6ce466a

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

types/src/data_types.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -699,20 +699,17 @@ fn parse_inner_type(input: &mut &str) -> Result<DataTypeNode, TypesError> {
699699

700700
let mut i = 0;
701701
while i < input_bytes.len() {
702-
if char_escaped {
703-
char_escaped = false;
704-
} else if input_bytes[i] == b'\\' {
705-
char_escaped = true;
706-
} else if input_bytes[i] == b'\'' {
707-
quote_open = !quote_open; // unescaped quote
708-
} else if !quote_open {
709-
if input_bytes[i] == b'(' {
710-
open_parens += 1;
711-
} else if input_bytes[i] == b')' {
712-
open_parens -= 1;
713-
} else if input_bytes[i] == b',' && open_parens == 0 {
714-
break;
715-
}
702+
match input_bytes[i] {
703+
_ if char_escaped => char_escaped = false,
704+
b'\\' if quote_open => char_escaped = true,
705+
b'\'' => quote_open = !quote_open, // unescaped quote
706+
byte if !quote_open => match byte {
707+
b'(' => open_parens += 1,
708+
b',' | b')' if open_parens == 0 => break,
709+
b')' => open_parens -= 1,
710+
_ => {}
711+
},
712+
_ => {}
716713
}
717714
i += 1;
718715
}
@@ -723,6 +720,14 @@ fn parse_inner_type(input: &mut &str) -> Result<DataTypeNode, TypesError> {
723720
&input[..i]
724721
))
725722
})?;
723+
724+
if open_parens != 0 || quote_open || char_escaped {
725+
return Err(TypesError::TypeParsingError(format!(
726+
"Invalid inner data type: {}",
727+
&input[..i]
728+
)));
729+
}
730+
726731
*input = &input[i..];
727732
DataTypeNode::new(&data_type_str)
728733
}

0 commit comments

Comments
 (0)