aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-07 20:25:30 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-07 20:27:13 +0800
commit67083d3173197c0a247f7b32300ee007749fa939 (patch)
treeb6845c08dc01caa79da6a7350509b8c7127cc56f
parenthooks: Simplify comments in the hook client (diff)
downloadforge-67083d3173197c0a247f7b32300ee007749fa939.tar.gz
forge-67083d3173197c0a247f7b32300ee007749fa939.tar.zst
forge-67083d3173197c0a247f7b32300ee007749fa939.zip
repo/index: Emit warning when path contains newline
-rw-r--r--http_handle_repo_index.go7
-rw-r--r--static/style.css8
-rw-r--r--templates/repo_index.tmpl6
-rw-r--r--utils.go15
4 files changed, 36 insertions, 0 deletions
diff --git a/http_handle_repo_index.go b/http_handle_repo_index.go
index 15b5173..6ac9b07 100644
--- a/http_handle_repo_index.go
+++ b/http_handle_repo_index.go
@@ -5,6 +5,7 @@ package main
import (
"net/http"
+ "strings"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
@@ -20,9 +21,14 @@ func handle_repo_index(w http.ResponseWriter, r *http.Request, params map[string
var recent_commits []*object.Commit
var commit_object *object.Commit
var tree *object.Tree
+ var notes []string
repo, repo_name, group_path = params["repo"].(*git.Repository), params["repo_name"].(string), params["group_path"].([]string)
+ if strings.Contains(repo_name, "\n") || slice_contains_newline(group_path) {
+ notes = append(notes, "Path contains newlines; HTTP Git access impossible")
+ }
+
ref_hash, err = get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string))
if err != nil {
goto no_ref
@@ -48,6 +54,7 @@ no_ref:
params["http_clone_url"] = generate_http_remote_url(group_path, repo_name)
params["ssh_clone_url"] = generate_ssh_remote_url(group_path, repo_name)
+ params["notes"] = notes
render_template(w, "repo_index", params)
}
diff --git a/static/style.css b/static/style.css
index 0c902d5..511f941 100644
--- a/static/style.css
+++ b/static/style.css
@@ -355,6 +355,14 @@ header#main-header > div#main-header-user {
display: flex;
align-items: center;
}
+
+/* Uncategorized */
table + table {
margin-top: 1rem;
}
+
+td > ul {
+ padding-left: 1.5rem;
+ margin-top: 0;
+ margin-bottom: 0;
+}
diff --git a/templates/repo_index.tmpl b/templates/repo_index.tmpl
index da67df4..c9d7311 100644
--- a/templates/repo_index.tmpl
+++ b/templates/repo_index.tmpl
@@ -33,6 +33,12 @@
<th scope="row">SSH remote</th>
<td><code>{{ .ssh_clone_url }}</code></td>
</tr>
+ {{ if .notes }}
+ <tr>
+ <th scope="row">Notes</th>
+ <td><ul>{{ range .notes }}<li>{{ . }}</li>{{ end }}</ul></td>
+ </tr>
+ {{ end }}
</tbody>
</table>
</div>
diff --git a/utils.go b/utils.go
new file mode 100644
index 0000000..f0b352d
--- /dev/null
+++ b/utils.go
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// SPDX-FileContributor: Runxi Yu <https://runxiyu.org>
+
+package main
+
+import "strings"
+
+func slice_contains_newline(s []string) bool {
+ for _, v := range s {
+ if strings.Contains(v, "\n") {
+ return true
+ }
+ }
+ return false
+}