mirror of
https://github.com/servo/servo.git
synced 2025-06-18 13:24:29 +00:00
url: Only truncate data URLs for Debug
(#32177)
Other types of URLs aren't so long that they need to be truncated.
This commit is contained in:
parent
4a12c06309
commit
adcaf2e881
1 changed files with 19 additions and 7 deletions
|
@ -23,6 +23,9 @@ pub use url::Host;
|
||||||
use url::{Position, Url};
|
use url::{Position, Url};
|
||||||
|
|
||||||
pub use crate::origin::{ImmutableOrigin, MutableOrigin, OpaqueOrigin};
|
pub use crate::origin::{ImmutableOrigin, MutableOrigin, OpaqueOrigin};
|
||||||
|
|
||||||
|
const DATA_URL_DISPLAY_LENGTH: usize = 40;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum UrlError {
|
pub enum UrlError {
|
||||||
SetUsername,
|
SetUsername,
|
||||||
|
@ -266,14 +269,23 @@ impl fmt::Display for ServoUrl {
|
||||||
|
|
||||||
impl fmt::Debug for ServoUrl {
|
impl fmt::Debug for ServoUrl {
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
if self.0.as_str().len() > 40 {
|
let url_string = self.0.as_str();
|
||||||
let mut hasher = DefaultHasher::new();
|
if self.scheme() != "data" || url_string.len() <= DATA_URL_DISPLAY_LENGTH {
|
||||||
hasher.write(self.0.as_str().as_bytes());
|
return url_string.fmt(formatter);
|
||||||
let truncated: String = self.0.as_str().chars().take(40).collect();
|
|
||||||
let result = format!("{}... ({:x})", truncated, hasher.finish());
|
|
||||||
return result.fmt(formatter);
|
|
||||||
}
|
}
|
||||||
self.0.fmt(formatter)
|
|
||||||
|
let mut hasher = DefaultHasher::new();
|
||||||
|
hasher.write(self.0.as_str().as_bytes());
|
||||||
|
|
||||||
|
format!(
|
||||||
|
"{}... ({:x})",
|
||||||
|
url_string
|
||||||
|
.chars()
|
||||||
|
.take(DATA_URL_DISPLAY_LENGTH)
|
||||||
|
.collect::<String>(),
|
||||||
|
hasher.finish()
|
||||||
|
)
|
||||||
|
.fmt(formatter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue