Check-in by ben on 2024-08-05 02:22:23

Escape vertical bar pipe | symbols in search results.

 INSERTED    DELETED
        6          0 src/cgi.awk
        3          2 src/search/index.dcgi.m4
        9          2 TOTAL over 2 changed files

Index: src/cgi.awk
==================================================================
--- src/cgi.awk
+++ src/cgi.awk
@@ -50,10 +50,16 @@
    split(path, parts, "/")
    topdir = parts[2]

    return
}
+
+function gph_encode(str) {
+    retval = str
+    gsub(/\|/, "\\|", retval)
+    return retval
+}

function uri_encode_init(     i, c) {
    for (i = 0; i <= 255; i++) {
        c = sprintf("%c", i)
        uri_encode_ord[c] = i

Index: src/search/index.dcgi.m4
==================================================================
--- src/search/index.dcgi.m4
+++ src/search/index.dcgi.m4
@@ -148,13 +148,14 @@
        } else if ($1 == ".response.docs[].title" && $2 == "s") {
            title = $3
            count++
            if (length(creator) > 0) {
                label = sprintf("[%s] %s by %s", mediatype[type], \
-                    shorten(title, 40), shorten(creator, 18))
+                    gph_encode(shorten(title, 40)), shorten(creator, 18))
            } else {
-                label = sprintf("[%s] %s", mediatype[type], shorten(title, 58))
+                label = sprintf("[%s] %s", mediatype[type], \
+                    gph_encode(shorten(title, 58)))
            }
            if (type == "collection") {
                printf "[1|%s|%s/search/%%09collection:(%s)|%s|%s]\n",
                    label, cgipath, id, server, port
            } else {