summaryrefslogtreecommitdiffstats
path: root/network/elinks/patches/0008-gopher-html-entities.patch
diff options
context:
space:
mode:
Diffstat (limited to 'network/elinks/patches/0008-gopher-html-entities.patch')
-rw-r--r--network/elinks/patches/0008-gopher-html-entities.patch47
1 files changed, 47 insertions, 0 deletions
diff --git a/network/elinks/patches/0008-gopher-html-entities.patch b/network/elinks/patches/0008-gopher-html-entities.patch
new file mode 100644
index 0000000000..750d1a49de
--- /dev/null
+++ b/network/elinks/patches/0008-gopher-html-entities.patch
@@ -0,0 +1,47 @@
+###################################################################
+# Encode < > to HTML.
+###################################################################
+diff -Naur '--exclude=.git' bb/src/protocol/gopher/gopher.c cc/src/protocol/gopher/gopher.c
+--- bb/src/protocol/gopher/gopher.c 2020-01-14 03:26:41.791778387 +0000
++++ cc/src/protocol/gopher/gopher.c 2020-01-14 06:19:56.964025440 +0000
+@@ -620,6 +620,25 @@
+ return line[0] == '.' && !line[1] ? NULL : line;
+ }
+
++/* substring replacement */
++static void
++str_replace(char * in_string, char * s_string, char * r_string)
++{
++ /* max == replace all characters */
++ char temp[strlen(in_string) * (strlen(r_string) - strlen(s_string)) + 1];
++ char * pos;
++
++ if (!(pos = strstr(in_string, s_string)))
++ return;
++
++ strncpy(temp, in_string, pos - in_string);
++ temp[pos - in_string] = 0;
++ sprintf(temp + (pos - in_string), "%s%s", r_string, pos + 1);
++ in_string[0] = 0;
++ strcpy(in_string, temp);
++ return str_replace(in_string, s_string, r_string);
++}
++
+ /* Parse a Gopher Menu document */
+ static struct connection_state
+ read_gopher_directory_data(struct connection *conn, struct read_buffer *rb)
+@@ -639,6 +658,14 @@
+ return connection_state(S_OUT_OF_MEM);
+ }
+
++ /* Lines with characters that need to be converted to html */
++ if (strstr(rb->data, "<")) {
++ str_replace(rb->data, "<", "&lt;");
++ }
++ if (strstr(rb->data, ">")) {
++ str_replace(rb->data, ">", "&gt;");
++ }
++
+ while ((end = get_gopher_line_end(rb->data, rb->length))) {
+ unsigned char *line = check_gopher_last_line(rb->data, end);
+