Skip to content

Commit 5ef0ba7

Browse files
bors[bot]justahero
andauthored
Merge #647
647: Fail parsing of missing display hint r=japaric a=justahero Before this change a format string was allowed to contain `{:}` without a display hint, which resulted in a `DisplayHint::NoHint`. Co-authored-by: Sebastian Ziebell <[email protected]>
2 parents 45a56ac + 5c21b20 commit 5ef0ba7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

parser/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ fn parse_param(mut input: &str, mode: ParserMode) -> Result<Param, Cow<'static,
340340
if input.starts_with(HINT_PREFIX) {
341341
// skip the prefix
342342
input = &input[HINT_PREFIX.len()..];
343+
if input.is_empty() {
344+
return Err("malformed format string (missing display hint after ':')".into());
345+
}
343346

344347
hint = Some(match parse_display_hint(input) {
345348
Some(a) => a,
@@ -1111,6 +1114,10 @@ mod tests {
11111114
parse("{0dunno}", ParserMode::Strict),
11121115
Err("unexpected content \"dunno\" in format string".into())
11131116
);
1117+
assert_eq!(
1118+
parse("{:}", ParserMode::Strict),
1119+
Err("malformed format string (missing display hint after ':')".into())
1120+
);
11141121
}
11151122

11161123
#[test]

0 commit comments

Comments
 (0)