Skip to content

Commit

Permalink
fix: logfmt: fixed keys deserialization logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed Mar 8, 2024
1 parent 966d811 commit e347e47
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 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.27.0-beta.1.1"
version = "0.27.0-beta.1.2"
edition = "2021"
build = "build.rs"

Expand Down
16 changes: 6 additions & 10 deletions src/logfmt/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'de> Deserializer<'de> {
parser: Parser {
input,
index: 0,
key: true,
key: false,
},
}
}
Expand Down Expand Up @@ -407,11 +407,9 @@ impl<'de> Parser<'de> {
fn parse_bool(&mut self) -> Result<bool> {
if self.tail().starts_with(b"true") {
self.advance(4);
self.key = !self.key;
Ok(true)
} else if self.tail().starts_with(b"false") {
self.advance(5);
self.key = !self.key;
Ok(false)
} else {
Err(Error::ExpectedBoolean)
Expand All @@ -436,7 +434,6 @@ impl<'de> Parser<'de> {
int += T::from(ch - b'0');
}
_ => {
self.key = !self.key;
return Ok(int);
}
}
Expand Down Expand Up @@ -467,7 +464,6 @@ impl<'de> Parser<'de> {
int += T::from((ch - b'0') as i8);
}
_ => {
self.key = !self.key;
if negative {
int = -int;
}
Expand All @@ -487,7 +483,6 @@ impl<'de> Parser<'de> {

fn parse_string<'s>(&'s mut self, scratch: &'s mut Vec<u8>, ignore: bool) -> Result<Reference<'de, 's, str>> {
if self.key {
self.key = false;
self.parse_key().map(Reference::Borrowed)
} else {
self.parse_value(scratch, ignore)
Expand All @@ -507,7 +502,6 @@ impl<'de> Parser<'de> {
break;
}
b'\x00'..=b' ' => {
self.key = true;
break;
}
b'\x80'..=b'\xFF' => {
Expand Down Expand Up @@ -569,7 +563,6 @@ impl<'de> Parser<'de> {
}
}

self.key = true;
if self.index == start {
return Ok("");
}
Expand Down Expand Up @@ -597,7 +590,6 @@ impl<'de> Parser<'de> {
}
match self.input[self.index] {
b'"' => {
self.key = true;
if no_escapes {
let borrowed = &self.input[start..self.index];
self.advance(1);
Expand Down Expand Up @@ -782,7 +774,11 @@ impl<'de, 'a> MapAccess<'de> for KeyValueSequence<'a, 'de> {
if self.de.parser.tail().len() == 0 {
return Ok(None);
}
seed.deserialize(&mut *self.de).map(Some)

self.de.parser.key = true;
let result = seed.deserialize(&mut *self.de).map(Some);
self.de.parser.key = false;
result
}

#[inline]
Expand Down

0 comments on commit e347e47

Please sign in to comment.