Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow whitespace control chars in EventId texts. #208

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion decodeme/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ impl<'a> Parser<'a> {

self.pos = end;

if self.full_text[start..end].iter().any(u8::is_ascii_control) {
if self.full_text[start..end]
.iter()
.filter(|x| !x.is_ascii_whitespace())
.any(u8::is_ascii_control)
{
return self.err("Found ASCII control character in <text>");
}

Expand Down Expand Up @@ -145,6 +149,14 @@ mod tests {
assert!(args.is_empty());
}

#[test]
fn parse_event_id_with_control_char() {
let (label, args) = Event::parse_event_id(Cow::from("foo\x1b"));

assert_eq!(label, "<parse error>");
assert!(args.is_empty());
}

#[test]
fn parse_event_id_one_arg() {
let (label, args) = Event::parse_event_id(Cow::from("foo\x1emy_arg"));
Expand All @@ -163,4 +175,22 @@ mod tests {
vec![Cow::from("arg1"), Cow::from("arg2"), Cow::from("arg3")]
);
}

#[test]
fn parse_event_id_args_with_whitespace() {
let (label, args) = Event::parse_event_id(Cow::from("foo\x1earg\n1\x1earg\t2\x1earg 3"));

assert_eq!(label, "foo");
assert_eq!(
args,
vec![Cow::from("arg\n1"), Cow::from("arg\t2"), Cow::from("arg 3")]
);
}

#[test]
fn parse_event_id_args_with_control_char() {
let (label, args) = Event::parse_event_id(Cow::from("foo\x1earg\x1b1"));
assert_eq!(label, "foo");
assert!(args.is_empty());
}
}
4 changes: 2 additions & 2 deletions measureme/src/event_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use crate::{Profiler, StringComponent, StringId};
/// <event_id> = <label> {<argument>}
/// <label> = <text>
/// <argument> = '\x1E' <text>
/// <text> = regex([^[[:cntrl:]]]+) // Anything but ASCII control characters
/// <text> = regex([[[:^cntrl:]][[:space:]]]+) // Anything but ASCII control characters except for whitespace.
/// ```
///
/// This means there's always a "label", followed by an optional list of
/// arguments. Future versions my support other optional suffixes (with a tag
/// arguments. Future versions may support other optional suffixes (with a tag
/// other than '\x11' after the '\x1E' separator), such as a "category".

/// The byte used to separate arguments from the label and each other.
Expand Down