Skip to content

Commit

Permalink
fix: fixed unwanted wrapping of a single hyphen in quotes (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus authored May 16, 2024
1 parent aa54ad2 commit 4f760e0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions 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 @@ members = [".", "crate/encstr"]
[workspace.package]
repository = "https://github.com/pamburus/hl"
authors = ["Pavel Ivanov <[email protected]>"]
version = "0.29.4-alpha.5"
version = "0.29.4-alpha.6"
edition = "2021"
license = "MIT"

Expand Down
15 changes: 15 additions & 0 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,21 @@ mod tests {
assert_eq!(format_no_color(&rec), format!(r#"k={}"#, v));
}

#[test]
fn test_string_value_json_hyphen() {
let v = "-";
let qv = format!(r#""{}""#, v);
let rec = Record::from_fields(&[("k", EncodedString::json(&qv).into())]);
assert_eq!(format_no_color(&rec), format!(r#"k={}"#, v));
}

#[test]
fn test_string_value_raw_hyphen() {
let v = "-";
let rec = Record::from_fields(&[("k", EncodedString::raw(&v).into())]);
assert_eq!(format_no_color(&rec), format!(r#"k={}"#, v));
}

#[test]
fn test_message_empty() {
let rec = Record {
Expand Down
17 changes: 9 additions & 8 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ pub fn looks_like_number(value: &[u8]) -> bool {
if s[0] == b'-' {
s = &s[1..];
}
s.iter().all(|&x| {
if x == b'.' {
n_dots += 1;
n_dots <= 1
} else {
x.is_ascii_digit()
}
})
s.len() != 0
&& s.iter().all(|&x| {
if x == b'.' {
n_dots += 1;
n_dots <= 1
} else {
x.is_ascii_digit()
}
})
}

// ---
Expand Down

0 comments on commit 4f760e0

Please sign in to comment.