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

fix: Fixed unwanted wrapping of a single hyphen in quotes #259

Merged
merged 1 commit into from
May 16, 2024
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
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 <mr.pavel.ivanov@gmail.com>"]
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