Skip to content

Commit

Permalink
Encode '(' and ')' in URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp authored and David Peter committed Nov 24, 2023
1 parent ec69a25 commit 25e3638
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions numbat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ impl Context {
}

pub fn print_info_for_keyword(&mut self, keyword: &str) -> Markup {
let url_encode = |s: &str| {
s.replace('(', "%28").replace(')', "%29")
};

if keyword.is_empty() {
return m::text("Usage: info <unit or variable>");
}
Expand All @@ -273,7 +277,7 @@ impl Context {
{
let mut help = m::text("Unit: ") + m::unit(md.name.as_deref().unwrap_or(keyword));
if let Some(url) = &md.url {
help += m::text(" (") + m::string(url) + m::text(")");
help += m::text(" (") + m::string(url_encode(url)) + m::text(")");
}
help += m::nl();
if md.aliases.len() > 1 {
Expand Down Expand Up @@ -347,7 +351,7 @@ impl Context {
help += m::identifier(keyword);
}
if let Some(url) = &l.metadata.url {
help += m::text(" (") + m::string(url) + m::text(")");
help += m::text(" (") + m::string(url_encode(url)) + m::text(")");
}
help += m::nl();

Expand Down

0 comments on commit 25e3638

Please sign in to comment.