From abc5b2a5bcd30df8060493a546f4bdbaea2e014c Mon Sep 17 00:00:00 2001 From: hyperion101010 Date: Mon, 21 Jan 2019 11:25:01 +0530 Subject: [PATCH] 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) } }