From f2d221a2f0d19213e6670510b111682d546f3876 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= jaakko.keranen@iki.fi
Date: Wed, 18 Aug 2021 06:53:37 +0300
Subject: [PATCH 1/1] GmRequest: Detect UTF-8 in local files of unknown type
src/gmutil.c | 41 +++++++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 14 deletions(-)
diff --git a/src/gmutil.c b/src/gmutil.c
index fda8489b..9bd74ee0 100644
--- a/src/gmutil.c
+++ b/src/gmutil.c
@@ -22,10 +22,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#include "gmutil.h"
-#include <the_Foundation/regexp.h>
+#include <the_Foundation/file.h>
+#include <the_Foundation/fileinfo.h>
#include <the_Foundation/object.h>
#include <the_Foundation/path.h>
#include <the_Foundation/regexp.h>
+#include <the_Foundation/regexp.h>
iRegExp *newGemtextLink_RegExp(void) {
return new_RegExp("=>\\s*([^\\s]+)(\\s.*)?", 0);
@@ -513,18 +515,6 @@ const char *mediaType_Path(const iString *path) {
if (endsWithCase_String(path, ".gmi") || endsWithCase_String(path, ".gemini")) {
return "text/gemini; charset=utf-8";
}
application/octet-stream if the contents fail to parse as UTF-8. */
endsWithCase_String(path, ".md") ||
endsWithCase_String(path, ".c") ||
endsWithCase_String(path, ".h") ||
endsWithCase_String(path, ".cc") ||
endsWithCase_String(path, ".hh") ||
endsWithCase_String(path, ".cpp") ||
endsWithCase_String(path, ".hpp")) {
return "text/plain";
else if (endsWithCase_String(path, ".pem")) {
return "application/x-pem-file";
}
@@ -558,7 +548,30 @@ const char *mediaType_Path(const iString *path) {
else if (endsWithCase_String(path, ".mid")) {
return "audio/midi";
}
endsWithCase_String(path, ".md") ||
endsWithCase_String(path, ".c") ||
endsWithCase_String(path, ".h") ||
endsWithCase_String(path, ".cc") ||
endsWithCase_String(path, ".hh") ||
endsWithCase_String(path, ".cpp") ||
endsWithCase_String(path, ".hpp")) {
return "text/plain";
iFile *f = new_File(path);
if (open_File(f, readOnly_FileMode)) {
iBlock *content = readAll_File(f);
if (isUtf8_Rangecc(range_Block(content))) {
mtype = "text/plain; charset=utf-8";
}
delete_Block(content);
}
iRelease(f);
}
static void replaceAllChars_String_(iString *d, char c, const char *replacement) {
--
2.25.1
text/plain
This content has been proxied by September (ba2dc).