diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Keep an overlong path out of the tab title
`fmt()` aborts the request rather than truncate, so a very long path
fed into a context-sensitive tab title took down page rendering.
| -rw-r--r-- | source/ui-shared.c | 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 15 insertions, 4 deletions
diff --git a/source/ui-shared.c b/source/ui-shared.c index 4084748..7cb8607 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -993,6 +993,17 @@ static const char *hc(const char *page) return strcmp(ctx.qry.page, page) ? NULL : "active"; } +/* Build a context-sensitive tab title such as "Commit history of <path>". + * fmt() aborts the request rather than truncate, so fall back to the plain + * label when the path is long enough to risk overflowing its buffer. */ +static const char *tab_title(const char *format, const char *generic, + const char *vpath) +{ + if (!vpath || !*vpath || strlen(vpath) > 256) + return generic; + return fmt(format, vpath); +} + static void cgit_print_path_crumbs(char *path) { char *old_path = ctx.qry.path; @@ -1114,19 +1125,19 @@ void cgit_print_pageheader(void) ctx.qry.oid, NULL); html("</li>\n<li>"); cgit_log_link("log", - vp && *vp ? fmt("Commit history of %s", vp) : "Commit history", + tab_title("Commit history of %s", "Commit history", vp), hc("log"), ctx.qry.head, NULL, ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg, ctx.qry.follow); html("</li>\n<li>"); if (ctx.qry.page && !strcmp(ctx.qry.page, "blame")) cgit_blame_link("blame", - vp && *vp ? fmt("Line-by-line blame of %s", vp) : "Blame", + tab_title("Line-by-line blame of %s", "Blame", vp), hc("blame"), ctx.qry.head, ctx.qry.oid, ctx.qry.vpath); else cgit_tree_link("tree", - vp && *vp ? fmt("Browse the tree at %s", vp) : "Browse the file tree", + tab_title("Browse the tree at %s", "Browse the file tree", vp), hc("tree"), ctx.qry.head, ctx.qry.oid, ctx.qry.vpath); html("</li>\n<li>"); @@ -1134,7 +1145,7 @@ void cgit_print_pageheader(void) ctx.qry.head, ctx.qry.oid, ctx.qry.vpath); html("</li>\n<li>"); cgit_diff_link("diff", - vp && *vp ? fmt("Changes to %s", vp) : "Changes in the current commit", + tab_title("Changes to %s", "Changes in the current commit", vp), hc("diff"), ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, ctx.qry.vpath); html("</li>\n"); |
