Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repository URLs sometimes end in .git in real-world usage #1170

Merged
merged 2 commits into from
Nov 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ impl<'a> MarkdownRenderer<'a> {
if !new_url.ends_with('/') {
new_url.push('/');
}
if new_url.ends_with(".git/") {
let offset = new_url.len() - 5;
new_url.drain(offset..offset + 4);
}
new_url += "blob/master";
if !url.starts_with('/') {
new_url.push('/');
Expand Down Expand Up @@ -310,11 +314,12 @@ mod tests {
let relative = "[there](there)";

for host in &["github.com", "gitlab.com", "bitbucket.org"] {
for &extra_slash in &[true, false] {
for (&extra_slash, &dot_git) in [true, false].iter().zip(&[true, false]) {
let url = format!(
"https://{}/rust-lang/test{}",
"https://{}/rust-lang/test{}{}",
host,
if extra_slash { "/" } else { "" }
if dot_git { ".git" } else { "" },
if extra_slash { "/" } else { "" },
);

let result = markdown_to_html(absolute, Some(&url)).unwrap();
Expand Down