From 6263f1d2e05b73d0358779b7b8d99c8251480386 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sun, 19 Jul 2026 15:34:16 -1000 Subject: Submit option forms without inline handlers --- assets/cgit.js | 18 ++++++++++++++++++ source/ui-diff.c | 6 +++--- source/ui-shared.c | 2 +- source/ui-stats.c | 4 ++-- tests/t0200-security.sh | 10 ++++++++++ 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/assets/cgit.js b/assets/cgit.js index 2164c1a..4e0ac70 100644 --- a/assets/cgit.js +++ b/assets/cgit.js @@ -73,6 +73,24 @@ document.addEventListener("DOMContentLoaded", function() { })(); +/* Selects marked data-autosubmit reload the page with the new setting. + * Wired here instead of inline onchange handlers, which a strict + * Content-Security-Policy blocks. Without scripting the forms keep + * their noscript reload button. */ + +(function () { + +document.addEventListener("DOMContentLoaded", function () { + var i, els = document.querySelectorAll("select[data-autosubmit]"); + + for (i = 0; i < els.length; i++) + els[i].addEventListener("change", function () { + this.form.submit(); + }); +}, false); + +})(); + /* Colour theme toggle: cycles auto -> light -> dark and remembers the * choice. "auto" leaves the page following the system preference via CSS. */ diff --git a/source/ui-diff.c b/source/ui-diff.c index c2f4717..baaa1f8 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -353,7 +353,7 @@ void cgit_print_diff_ctrls(void) html(""); html("context:"); html(""); - html(""); curr = ctx.qry.context; if (!curr) curr = 3; @@ -366,7 +366,7 @@ void cgit_print_diff_ctrls(void) html(""); html("space:"); html(""); - html(""); html_intoption(0, "include", ctx.qry.ignorews); html_intoption(1, "ignore", ctx.qry.ignorews); html(""); @@ -374,7 +374,7 @@ void cgit_print_diff_ctrls(void) html(""); html("mode:"); html(""); - html(""); curr = ctx.qry.has_difftype ? ctx.qry.difftype : ctx.cfg.difftype; html_intoption(0, "unified", curr); html_intoption(1, "ssdiff", curr); diff --git a/source/ui-shared.c b/source/ui-shared.c index c7a91e2..df7ad1f 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1064,7 +1064,7 @@ static void print_header(void) if (ctx.repo && ctx.env.authenticated) { html("
\n"); cgit_add_hidden_formfields(0, 1, ctx.qry.page); - html("\n"); refs_for_each_branch_ref(get_main_ref_store(the_repository), print_branch_option, ctx.qry.head); if (ctx.repo->enable_remote_branches) diff --git a/source/ui-stats.c b/source/ui-stats.c index d33441b..cabbc3c 100644 --- a/source/ui-stats.c +++ b/source/ui-stats.c @@ -405,14 +405,14 @@ void cgit_show_stats(void) html(""); if (ctx.repo->max_stats > 1) { html(""); - html(""); } html(""); - html("
Period:
Authors: