From abc5b2a5bcd30df8060493a546f4bdbaea2e014c Mon Sep 17 00:00:00 2001 From: hyperion101010 Date: Mon, 21 Jan 2019 11:25:01 +0530 Subject: [PATCH 1/3] Truncate long URLs when doing debug prints I added the required changes on debug in lib.rs file, you can have a review --- components/url/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/url/lib.rs b/components/url/lib.rs index 0133065d533..b8ab58abeb6 100644 --- a/components/url/lib.rs +++ b/components/url/lib.rs @@ -17,7 +17,9 @@ pub mod origin; pub use crate::origin::{ImmutableOrigin, MutableOrigin, OpaqueOrigin}; +use std::collections::hash_map::DefaultHasher; use std::fmt; +use std::hash::Hasher; use std::net::IpAddr; use std::ops::{Index, Range, RangeFrom, RangeFull, RangeTo}; use std::path::Path; @@ -169,6 +171,12 @@ impl fmt::Display for ServoUrl { impl fmt::Debug for ServoUrl { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + if self.0.as_str().len() > 40 { + let hasher = DefaultHasher::new(); + let truncated: String = self.0.as_str().chars().take(40).collect(); + let result = format!("{}... ({})", truncated, hasher.finish().to_string()); + return result.fmt(formatter); + } self.0.fmt(formatter) } } From 416822738232d4a020c81ea459b62017a269f2ea Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 28 Jan 2019 15:13:45 -0500 Subject: [PATCH 2/3] Use hex for debug url hash. --- components/url/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/url/lib.rs b/components/url/lib.rs index b8ab58abeb6..fe34c9ebe2b 100644 --- a/components/url/lib.rs +++ b/components/url/lib.rs @@ -174,7 +174,7 @@ impl fmt::Debug for ServoUrl { if self.0.as_str().len() > 40 { let hasher = DefaultHasher::new(); let truncated: String = self.0.as_str().chars().take(40).collect(); - let result = format!("{}... ({})", truncated, hasher.finish().to_string()); + let result = format!("{}... ({:x})", truncated, hasher.finish().to_string()); return result.fmt(formatter); } self.0.fmt(formatter) From 21e10b201a272a806b72d412b946a53d00436367 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 28 Jan 2019 15:56:13 -0500 Subject: [PATCH 3/3] Don't convert hash to string. --- components/url/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/url/lib.rs b/components/url/lib.rs index fe34c9ebe2b..dccd27a8b00 100644 --- a/components/url/lib.rs +++ b/components/url/lib.rs @@ -174,7 +174,7 @@ impl fmt::Debug for ServoUrl { if self.0.as_str().len() > 40 { let hasher = DefaultHasher::new(); let truncated: String = self.0.as_str().chars().take(40).collect(); - let result = format!("{}... ({:x})", truncated, hasher.finish().to_string()); + let result = format!("{}... ({:x})", truncated, hasher.finish()); return result.fmt(formatter); } self.0.fmt(formatter)