Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4f760e0

Browse files
authoredMay 16, 2024··
fix: fixed unwanted wrapping of a single hyphen in quotes (#259)
1 parent aa54ad2 commit 4f760e0

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed
 

‎Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ members = [".", "crate/encstr"]
44
[workspace.package]
55
repository = "https://github.com/pamburus/hl"
66
authors = ["Pavel Ivanov <mr.pavel.ivanov@gmail.com>"]
7-
version = "0.29.4-alpha.5"
7+
version = "0.29.4-alpha.6"
88
edition = "2021"
99
license = "MIT"
1010

‎src/formatting.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,21 @@ mod tests {
12831283
assert_eq!(format_no_color(&rec), format!(r#"k={}"#, v));
12841284
}
12851285

1286+
#[test]
1287+
fn test_string_value_json_hyphen() {
1288+
let v = "-";
1289+
let qv = format!(r#""{}""#, v);
1290+
let rec = Record::from_fields(&[("k", EncodedString::json(&qv).into())]);
1291+
assert_eq!(format_no_color(&rec), format!(r#"k={}"#, v));
1292+
}
1293+
1294+
#[test]
1295+
fn test_string_value_raw_hyphen() {
1296+
let v = "-";
1297+
let rec = Record::from_fields(&[("k", EncodedString::raw(&v).into())]);
1298+
assert_eq!(format_no_color(&rec), format!(r#"k={}"#, v));
1299+
}
1300+
12861301
#[test]
12871302
fn test_message_empty() {
12881303
let rec = Record {

‎src/model.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ pub fn looks_like_number(value: &[u8]) -> bool {
4646
if s[0] == b'-' {
4747
s = &s[1..];
4848
}
49-
s.iter().all(|&x| {
50-
if x == b'.' {
51-
n_dots += 1;
52-
n_dots <= 1
53-
} else {
54-
x.is_ascii_digit()
55-
}
56-
})
49+
s.len() != 0
50+
&& s.iter().all(|&x| {
51+
if x == b'.' {
52+
n_dots += 1;
53+
n_dots <= 1
54+
} else {
55+
x.is_ascii_digit()
56+
}
57+
})
5758
}
5859

5960
// ---

0 commit comments

Comments
 (0)
Please sign in to comment.