Skip to content

Commit

Permalink
fix: ignore case in predefined field keys in filters
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed Oct 11, 2023
1 parent cf82428 commit 2cf5bc3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ categories = ["command-line-utilities"]
description = "Utility for viewing json-formatted log files."
keywords = ["cli", "human", "log"]
name = "hl"
version = "0.20.0-beta.14.8.2"
version = "0.20.0-beta.14.9"
edition = "2021"
build = "build.rs"

Expand Down
19 changes: 10 additions & 9 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,11 @@ impl<'a> KeyMatcher<'a> {
}

pub fn match_key<'b>(&'b self, key: &str) -> Option<KeyMatch<'a>> {
let norm = |b: u8| {
if b == b'_' {
b'-'
} else {
b.to_ascii_lowercase()
}
};
let bytes = self.key.as_bytes();
if bytes
.iter()
.zip(key.as_bytes().iter())
.position(|(&x, &y)| norm(x) != norm(y))
.position(|(&x, &y)| Self::norm(x.into()) != Self::norm(y.into()))
.is_some()
{
return None;
Expand All @@ -352,6 +345,14 @@ impl<'a> KeyMatcher<'a> {
None
}
}

fn norm(c: char) -> char {
if c == '_' {
'-'
} else {
c.to_ascii_lowercase()
}
}
}

// ---
Expand Down Expand Up @@ -413,7 +414,7 @@ impl FieldFilter {
let (key, match_policy, op) = Self::parse_mp_op(key, value)?;
let flat_key = key.as_bytes().iter().position(|&x| x == b'.').is_none();
Ok(Self {
key: key.into(),
key: key.chars().map(KeyMatcher::norm).collect(),
match_policy,
op,
flat_key,
Expand Down

0 comments on commit 2cf5bc3

Please sign in to comment.