Skip to content

Commit e136131

Browse files
andjo403michaelwoerister
authored andcommitted
Allow whitespace control chars in EventId texts.
1 parent 0433c25 commit e136131

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

decodeme/src/event.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ impl<'a> Parser<'a> {
9393

9494
self.pos = end;
9595

96-
if self.full_text[start..end].iter().any(u8::is_ascii_control) {
96+
if self.full_text[start..end]
97+
.iter()
98+
.filter(|x| !x.is_ascii_whitespace())
99+
.any(u8::is_ascii_control)
100+
{
97101
return self.err("Found ASCII control character in <text>");
98102
}
99103

@@ -145,6 +149,14 @@ mod tests {
145149
assert!(args.is_empty());
146150
}
147151

152+
#[test]
153+
fn parse_event_id_with_control_char() {
154+
let (label, args) = Event::parse_event_id(Cow::from("foo\x1b"));
155+
156+
assert_eq!(label, "<parse error>");
157+
assert!(args.is_empty());
158+
}
159+
148160
#[test]
149161
fn parse_event_id_one_arg() {
150162
let (label, args) = Event::parse_event_id(Cow::from("foo\x1emy_arg"));
@@ -163,4 +175,22 @@ mod tests {
163175
vec![Cow::from("arg1"), Cow::from("arg2"), Cow::from("arg3")]
164176
);
165177
}
178+
179+
#[test]
180+
fn parse_event_id_args_with_whitespace() {
181+
let (label, args) = Event::parse_event_id(Cow::from("foo\x1earg\n1\x1earg\t2\x1earg 3"));
182+
183+
assert_eq!(label, "foo");
184+
assert_eq!(
185+
args,
186+
vec![Cow::from("arg\n1"), Cow::from("arg\t2"), Cow::from("arg 3")]
187+
);
188+
}
189+
190+
#[test]
191+
fn parse_event_id_args_with_control_char() {
192+
let (label, args) = Event::parse_event_id(Cow::from("foo\x1earg\x1b1"));
193+
assert_eq!(label, "foo");
194+
assert!(args.is_empty());
195+
}
166196
}

measureme/src/event_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use crate::{Profiler, StringComponent, StringId};
88
/// <event_id> = <label> {<argument>}
99
/// <label> = <text>
1010
/// <argument> = '\x1E' <text>
11-
/// <text> = regex([^[[:cntrl:]]]+) // Anything but ASCII control characters
11+
/// <text> = regex([[[:^cntrl:]][[:space:]]]+) // Anything but ASCII control characters except for whitespace.
1212
/// ```
1313
///
1414
/// This means there's always a "label", followed by an optional list of
15-
/// arguments. Future versions my support other optional suffixes (with a tag
15+
/// arguments. Future versions may support other optional suffixes (with a tag
1616
/// other than '\x11' after the '\x1E' separator), such as a "category".
1717
1818
/// The byte used to separate arguments from the label and each other.

0 commit comments

Comments
 (0)