From fb63600102a133a594b03872e754e16bd4a199c9 Mon Sep 17 00:00:00 2001 From: Alex Whitney Date: Thu, 4 Jul 2024 10:15:36 +0100 Subject: [PATCH 1/3] Debug fmt handles unicode boundaries --- crux_http/src/protocol.rs | 7 ++++--- crux_kv/src/lib.rs | 2 +- crux_kv/src/tests.rs | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crux_http/src/protocol.rs b/crux_http/src/protocol.rs index 5c711cc9a..dd5533d5b 100644 --- a/crux_http/src/protocol.rs +++ b/crux_http/src/protocol.rs @@ -36,7 +36,7 @@ impl std::fmt::Debug for HttpRequest { if s.len() < 50 { format!("\"{s}\"") } else { - format!("\"{}\"...", &s[..50]) + format!("\"{}\"...", &s.chars().take(50).collect::()) } } else { format!("", self.body.len()) @@ -310,12 +310,13 @@ mod tests { { // big let req = HttpRequest::post("http://example.com") - .body("abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz") + // we check that we handle unicode boundaries correctly + .body("abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstu😀😀😀😀😀😀") .build(); let repr = format!("{req:?}"); assert_eq!( repr, - r#"HttpReqeuest { method: "POST", url: "http://example.com", body: "abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvw"... }"# + r#"HttpReqeuest { method: "POST", url: "http://example.com", body: "abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstu😀😀"... }"# ); } diff --git a/crux_kv/src/lib.rs b/crux_kv/src/lib.rs index fba72f38b..452d3ca2e 100644 --- a/crux_kv/src/lib.rs +++ b/crux_kv/src/lib.rs @@ -49,7 +49,7 @@ impl std::fmt::Debug for KeyValueOperation { if s.len() < 50 { format!("\"{s}\"") } else { - format!("\"{}\"...", &s[..50]) + format!("\"{}\"...", &s.chars().take(50).collect::()) } } else { format!("", value.len()) diff --git a/crux_kv/src/tests.rs b/crux_kv/src/tests.rs index 53ecfbb92..831f23b65 100644 --- a/crux_kv/src/tests.rs +++ b/crux_kv/src/tests.rs @@ -395,13 +395,13 @@ fn test_kv_operation_debug_repr() { let op = KeyValueOperation::Set { key: "my key".into(), value: - b"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz" - .to_vec(), + // we check that we handle unicode boundaries correctly + "abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstu😀😀😀😀😀😀".as_bytes().to_vec(), }; let repr = format!("{op:?}"); assert_eq!( repr, - r#"Set { key: "my key", value: "abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvw"... }"# + r#"Set { key: "my key", value: "abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstu😀😀"... }"# ); } From 64378df2b2f2d1f5e69cd001caddbb053377c95e Mon Sep 17 00:00:00 2001 From: Alex Whitney Date: Thu, 4 Jul 2024 10:18:35 +0100 Subject: [PATCH 2/3] minor clippy fixes --- crux_http/src/protocol.rs | 2 +- crux_kv/src/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crux_http/src/protocol.rs b/crux_http/src/protocol.rs index dd5533d5b..b4238a27f 100644 --- a/crux_http/src/protocol.rs +++ b/crux_http/src/protocol.rs @@ -36,7 +36,7 @@ impl std::fmt::Debug for HttpRequest { if s.len() < 50 { format!("\"{s}\"") } else { - format!("\"{}\"...", &s.chars().take(50).collect::()) + format!("\"{}\"...", s.chars().take(50).collect::()) } } else { format!("", self.body.len()) diff --git a/crux_kv/src/lib.rs b/crux_kv/src/lib.rs index 452d3ca2e..c632da86a 100644 --- a/crux_kv/src/lib.rs +++ b/crux_kv/src/lib.rs @@ -45,11 +45,11 @@ impl std::fmt::Debug for KeyValueOperation { match self { KeyValueOperation::Get { key } => f.debug_struct("Get").field("key", key).finish(), KeyValueOperation::Set { key, value } => { - let body_repr = if let Ok(s) = std::str::from_utf8(&value) { + let body_repr = if let Ok(s) = std::str::from_utf8(value) { if s.len() < 50 { format!("\"{s}\"") } else { - format!("\"{}\"...", &s.chars().take(50).collect::()) + format!("\"{}\"...", s.chars().take(50).collect::()) } } else { format!("", value.len()) From 4424c9154b4c8137b8709531f38a2f112eb510d4 Mon Sep 17 00:00:00 2001 From: Alex Whitney Date: Thu, 4 Jul 2024 10:21:05 +0100 Subject: [PATCH 3/3] update pnpm action version --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fbe20d1a3..7b5501fff 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -46,7 +46,7 @@ jobs: - name: Run sccache-cache uses: mozilla-actions/sccache-action@v0.0.3 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: latest