Skip to content

Commit 6da2c90

Browse files
committed
fix: new reject case
Signed-off-by: cutecutecat <junyuchen@tensorchord.ai>
1 parent 4d5bd93 commit 6da2c90

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/utils/parse.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ where
107107
if input.is_empty() {
108108
return Err(ParseVectorError::EmptyString {});
109109
}
110-
let mut dims: usize = 0;
110+
let mut dims: usize = usize::MAX;
111111
let left = 'a: {
112112
for position in 0..input.len() - 1 {
113113
match input[position] {
@@ -130,6 +130,10 @@ where
130130
b'/' => {
131131
token.reverse();
132132
let s = unsafe { std::str::from_utf8_unchecked(&token[..]) };
133+
// two `dims` are found
134+
if dims != usize::MAX {
135+
return Err(ParseVectorError::BadCharacter { position });
136+
}
133137
dims = s
134138
.parse::<usize>()
135139
.map_err(|_| ParseVectorError::BadParsing { position })?;
@@ -144,6 +148,12 @@ where
144148
}
145149
return Err(ParseVectorError::BadParentheses { character: '}' });
146150
};
151+
// `dims` is not found
152+
if dims == usize::MAX {
153+
return Err(ParseVectorError::BadCharacter {
154+
position: input.len(),
155+
});
156+
}
147157
let mut indexes = Vec::<u32>::new();
148158
let mut values = Vec::<T>::new();
149159
let mut index: u32 = u32::MAX;
@@ -203,6 +213,9 @@ where
203213
_ => return Err(ParseVectorError::BadCharacter { position }),
204214
}
205215
}
216+
// A valid case is either
217+
// - empty string: ""
218+
// - end with number when a index is extracted:"1:2, 3:4"
206219
if state != ParseState::Start && (state != ParseState::Number || index == u32::MAX) {
207220
return Err(ParseVectorError::BadCharacter { position: right });
208221
}
@@ -283,6 +296,7 @@ mod tests {
283296
"{0:, 1:2}/5",
284297
"{0:1, 1}/5",
285298
"/2",
299+
"{}/1/2",
286300
];
287301
for e in exprs {
288302
let ret = parse_pgvector_svector(e.as_bytes(), |s| s.parse::<F32>().ok());

0 commit comments

Comments
 (0)