mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 10:04:12 +02:00
fix extracting format string messages
This commit is contained in:
parent
68282f67af
commit
5e73134c37
3 changed files with 101 additions and 76 deletions
|
|
@ -31,3 +31,7 @@ cc = "1.1.6"
|
|||
maplit = "1.0.2"
|
||||
test-case = "3.3.1"
|
||||
insta = { version = "1.39.0", features = ["json"] }
|
||||
|
||||
[profile.profiling]
|
||||
inherits = "release"
|
||||
debug = true
|
||||
|
|
@ -28,7 +28,7 @@ impl MessageBuilder {
|
|||
start = placeholder.end();
|
||||
}
|
||||
if start < content.len() {
|
||||
Self::push_literal_inner(&mut self.parts, content)
|
||||
Self::push_literal_inner(&mut self.parts, &content[start..])
|
||||
}
|
||||
} else {
|
||||
Self::push_literal_inner(&mut self.parts, content)
|
||||
|
|
@ -200,3 +200,24 @@ fn test_printf() {
|
|||
builder.parts
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_push_pattern_literal() {
|
||||
fn push_str(str: &str) -> Vec<MessagePart> {
|
||||
let mut builder = MessageBuilder::with_capacity(4);
|
||||
builder.push_literal(str);
|
||||
builder.parts
|
||||
}
|
||||
assert_eq!(
|
||||
vec![
|
||||
MessagePart::Literal(r#"Trusted domain error. ""#.into()),
|
||||
MessagePart::PlaceHolder(r#"{remoteAddress}"#.into()),
|
||||
MessagePart::Literal(r#"" tried to access using ""#.into()),
|
||||
MessagePart::PlaceHolder(r#"{host}"#.into()),
|
||||
MessagePart::Literal(r#"" as host."#.into()),
|
||||
],
|
||||
push_str(
|
||||
r#"Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host."#
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue