Commit Diff


commit - a2fd3805b0807d0e85411613df26bd6dcaed01ce
commit + c0b634ddc444df1c2391e8262cf707e4422287a6
blob - 38c23eb99a604a05c94508b2afdc5c1baf64681b
blob + d2e022296c4631c71eaf44cf3904ce86277840b0
--- ChangeLog
+++ ChangeLog
@@ -1,5 +1,7 @@
 2021-07-06  Omar Polo  <op@omarpolo.com>
 
+	* parser.c (parser_foreach_line): deal with BOM
+
 	* telescope.c (handle_check_cert_user_choice): fix two bug: don't crash when there's a certificate mismatch and after saving the cert, before choosing to persist it, the page gets redirected.  Now when the user accept a certificate, is treated as temporary saved for the whole session.
 
 	* defaults.c (load_default_keys): bind M-prior/next (M-pageup/pagedown) to tab-previous and tab-next
blob - d18eb68301dff0ee3b7e7109fa1fb8d21ff013e9
blob + 0434603c519c7ff93382ba4dc6e6f938b55a2ad2
--- parser.c
+++ parser.c
@@ -75,6 +75,23 @@ parser_foreach_line(struct parser *p, const char *buf,
 	b = p->buf;
 	len = p->len;
 
+	if (!p->in_body && len < 3)
+		return 1;
+
+	if (!p->in_body) {
+		p->in_body = 1;
+
+		/*
+		 * drop the BOM: only UTF-8 is supported, and there
+		 * it's useless; some editors may still add one
+		 * though.
+		 */
+		if (memmem(b, len, "\xEF\xBB\xBF", 3) == b) {
+			b += 3;
+			len -= 3;
+		}
+	}
+
 	/* drop every "funny" ASCII character */
 	for (i = 0; i < len; ) {
 		ch = b[i];
blob - 54c23576691a715aa722570bb81528d86e78b7ec
blob + c0397fc1e674ee0325c190c22d9ef8a6b70529ca
--- telescope.h
+++ telescope.h
@@ -158,6 +158,7 @@ struct parser {
 	const char	*name;
 	char		 title[32+1];
 	char		*buf;
+	int		 in_body; /* used to deal with BOM */
 	size_t		 len;
 	size_t		 cap;
 	int		 flags;