From 75a5bdedbe3299b4a8d58239fd6d4ddaf52c8e5b Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 29 Mar 2024 16:32:04 +0100 Subject: ansi2html: support passing titles Use content type attributes so e.g. git.cgi can set the title even with a text/x-ansi content type. (This commit also fixes some bugs in content type attribute handling.) --- bonus/git.cgi | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'bonus/git.cgi') diff --git a/bonus/git.cgi b/bonus/git.cgi index 1f93862a..387f3a64 100755 --- a/bonus/git.cgi +++ b/bonus/git.cgi @@ -27,12 +27,7 @@ for (const p of std.getenv("QUERY_STRING").split('&')) { } function startGitCmd(config, params) { - const titleParams = params.join(' ').replace(/[&<>]/g, - x => ({'&': '&', '<': '<', '>': '>'}[x])); - std.out.puts(`Content-Type: text/html - - -git ${titleParams}`); + std.out.puts("Content-Type: text/html\n\n"); std.out.flush(); const [read_fd, write_fd] = os.pipe(); const [read_fd2, write_fd2] = os.pipe(); @@ -43,7 +38,8 @@ function startGitCmd(config, params) { os.close(write_fd); const libexecDir = std.getenv("CHA_LIBEXEC_DIR") ?? '/usr/local/libexec/chawan'; - os.exec([libexecDir + "/ansi2html"], { + const title = encodeURIComponent('git ' + params.join(' ')); + os.exec([libexecDir + "/ansi2html", "-st", title], { stdin: read_fd, stdout: write_fd2, block: false @@ -78,7 +74,8 @@ if (params[0] == "log") { } f.close(); } else { - std.out.puts("Content-Type: text/x-ansi\n\n"); + const title = encodeURIComponent('git ' + params.join(' ')); + std.out.puts(`Content-Type: text/x-ansi;title=${title}\n\n`); std.out.flush(); const pid = os.exec(["git", ...config, ...params], { block: false, -- cgit 1.4.1-2-gfad0