diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Percent-encode file paths in side-by-side diffs
Diffstat (limited to 'source')
| -rw-r--r-- | source/ui-ssdiff.c | 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 16 insertions, 2 deletions
diff --git a/source/ui-ssdiff.c b/source/ui-ssdiff.c index af8bc9e..ed5a2f4 100644 --- a/source/ui-ssdiff.c +++ b/source/ui-ssdiff.c @@ -237,13 +237,20 @@ static void print_ssdiff_line(char *class, struct diff_filespec *old_file = cgit_get_current_old_file(); char *lineno_str = fmt("n%d", old_line_no); char *id_str = fmt("id=%s#%s", is_null_oid(&old_file->oid)?"HEAD":oid_to_hex(old_rev_oid), lineno_str); - char *fileurl = cgit_fileurl(ctx.repo->url, "tree", old_file->path, id_str); + struct strbuf path = STRBUF_INIT; + char *fileurl; + // The file path is repository content, so percent-encode it + // before it lands raw in the href below. + if (old_file->path) + strbuf_add_percentencode(&path, old_file->path, 0); + fileurl = cgit_fileurl(ctx.repo->url, "tree", path.buf, id_str); html("<td class='lineno'><a href='"); html(fileurl); htmlf("'>%s</a>", lineno_str + 1); html("</td>"); htmlf("<td class='%s'>", class); free(fileurl); + strbuf_release(&path); } else if (old_line) htmlf("<td class='lineno'></td><td class='%s'>", class); else @@ -260,13 +267,20 @@ static void print_ssdiff_line(char *class, struct diff_filespec *new_file = cgit_get_current_new_file(); char *lineno_str = fmt("n%d", new_line_no); char *id_str = fmt("id=%s#%s", is_null_oid(&new_file->oid)?"HEAD":oid_to_hex(new_rev_oid), lineno_str); - char *fileurl = cgit_fileurl(ctx.repo->url, "tree", new_file->path, id_str); + struct strbuf path = STRBUF_INIT; + char *fileurl; + // The file path is repository content, so percent-encode it + // before it lands raw in the href below. + if (new_file->path) + strbuf_add_percentencode(&path, new_file->path, 0); + fileurl = cgit_fileurl(ctx.repo->url, "tree", path.buf, id_str); html("<td class='lineno'><a href='"); html(fileurl); htmlf("'>%s</a>", lineno_str + 1); html("</td>"); htmlf("<td class='%s'>", class); free(fileurl); + strbuf_release(&path); } else if (new_line) htmlf("<td class='lineno'></td><td class='%s'>", class); else |
