From 672a534a044d811aa57e927288de50360882ac54 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 13 Feb 2022 20:57:09 +0200 Subject: Added a preference for maximum URL size The setting defaults to 8 KB. Link lines with longer URLs are not recognized as links. --- src/app.c | 12 ++++++++++++ src/gmdocument.c | 17 +++++++++-------- src/prefs.c | 1 + src/prefs.h | 1 + src/ui/util.c | 1 + 5 files changed, 24 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index 0f9249cc..a2ada36e 100644 --- a/src/app.c +++ b/src/app.c @@ -244,6 +244,7 @@ static iString *serializePrefs_App_(const iApp *d) { appendFormat_String(str, "imageloadscroll arg:%d\n", d->prefs.loadImageInsteadOfScrolling); appendFormat_String(str, "cachesize.set arg:%d\n", d->prefs.maxCacheSize); appendFormat_String(str, "memorysize.set arg:%d\n", d->prefs.maxMemorySize); + appendFormat_String(str, "urlsize.set arg:%d\n", d->prefs.maxUrlSize); appendFormat_String(str, "decodeurls arg:%d\n", d->prefs.decodeUserVisibleURLs); appendFormat_String(str, "linewidth.set arg:%d\n", d->prefs.lineWidth); appendFormat_String(str, "linespacing.set arg:%f\n", d->prefs.lineSpacing); @@ -1974,6 +1975,8 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { toInt_String(text_InputWidget(findChild_Widget(d, "prefs.cachesize")))); postCommandf_App("memorysize.set arg:%d", toInt_String(text_InputWidget(findChild_Widget(d, "prefs.memorysize")))); + postCommandf_App("urlsize.set arg:%d", + toInt_String(text_InputWidget(findChild_Widget(d, "prefs.urlsize")))); postCommandf_App("ca.file path:%s", cstrText_InputWidget(findChild_Widget(d, "prefs.ca.file"))); postCommandf_App("ca.path path:%s", @@ -2771,6 +2774,13 @@ iBool handleCommand_App(const char *cmd) { } return iTrue; } + else if (equal_Command(cmd, "urlsize.set")) { + d->prefs.maxUrlSize = arg_Command(cmd); + if (d->prefs.maxUrlSize < 1024) { + d->prefs.maxUrlSize = 1024; /* Gemini protocol requirement */ + } + return iTrue; + } else if (equal_Command(cmd, "searchurl")) { iString *url = &d->prefs.strings[searchUrl_PrefsString]; setCStr_String(url, suffixPtr_Command(cmd, "address")); @@ -3158,6 +3168,8 @@ iBool handleCommand_App(const char *cmd) { collectNewFormat_String("%d", d->prefs.maxCacheSize)); setText_InputWidget(findChild_Widget(dlg, "prefs.memorysize"), collectNewFormat_String("%d", d->prefs.maxMemorySize)); + setText_InputWidget(findChild_Widget(dlg, "prefs.urlsize"), + collectNewFormat_String("%d", d->prefs.maxUrlSize)); setToggle_Widget(findChild_Widget(dlg, "prefs.decodeurls"), d->prefs.decodeUserVisibleURLs); setText_InputWidget(findChild_Widget(dlg, "prefs.searchurl"), &d->prefs.strings[searchUrl_PrefsString]); setText_InputWidget(findChild_Widget(dlg, "prefs.ca.file"), &d->prefs.strings[caFile_PrefsString]); diff --git a/src/gmdocument.c b/src/gmdocument.c index 63d100e2..5cae4138 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c @@ -333,13 +333,14 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li link->urlRange = capturedRange_RegExpMatch(&m, 1); setRange_String(&link->url, link->urlRange); set_String(&link->url, canonicalUrl_String(absoluteUrl_String(&d->url, &link->url))); - if (startsWithCase_String(&link->url, "about:command")) { - /* This is a special internal page that allows submitting UI events. */ - if (!d->enableCommandLinks) { - delete_GmLink(link); - *linkId = 0; - return line; - } + /* If invalid, disregard the link. */ + if (size_String(&link->url) > prefs_App()->maxUrlSize || + (startsWithCase_String(&link->url, "about:command") + /* this is a special internal page that allows submitting UI events */ + && !d->enableCommandLinks)) { + delete_GmLink(link); + *linkId = 0; + return line; } /* Check the URL. */ { iUrl parts; @@ -385,7 +386,7 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li iString *path = newRange_String(parts.path); if (endsWithCase_String(path, ".gif") || endsWithCase_String(path, ".jpg") || endsWithCase_String(path, ".jpeg") || endsWithCase_String(path, ".png") || - endsWithCase_String(path, ".tga") || endsWithCase_String(path, ".psd") || + endsWithCase_String(path, ".tga") || endsWithCase_String(path, ".psd") || #if defined (LAGRANGE_ENABLE_WEBP) endsWithCase_String(path, ".webp") || #endif diff --git a/src/prefs.c b/src/prefs.c index 13a1dab7..cd86bf60 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -73,6 +73,7 @@ void init_Prefs(iPrefs *d) { d->decodeUserVisibleURLs = iTrue; d->maxCacheSize = 10; d->maxMemorySize = 200; + d->maxUrlSize = 8192; setCStr_String(&d->strings[uiFont_PrefsString], "default"); setCStr_String(&d->strings[headingFont_PrefsString], "default"); setCStr_String(&d->strings[bodyFont_PrefsString], "default"); diff --git a/src/prefs.h b/src/prefs.h index ea864f51..25bf56c4 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -172,6 +172,7 @@ struct Impl_Prefs { /* Network */ int maxCacheSize; /* MB */ int maxMemorySize; /* MB */ + int maxUrlSize; /* bytes; longer ones will be disregarded */ /* Style */ iStringSet * disabledFontPacks; int gemtextAnsiEscapes; diff --git a/src/ui/util.c b/src/ui/util.c index 41f8eaa9..53ee8fda 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -2902,6 +2902,7 @@ iWidget *makePreferences_Widget(void) { appendTwoColumnTabPage_Widget(tabs, "${heading.prefs.network}", '6', &headings, &values); addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.decodeurls}"))); addChild_Widget(values, iClob(makeToggle_Widget("prefs.decodeurls"))); + addPrefsInputWithHeading_(headings, values, "prefs.urlsize", iClob(new_InputWidget(10))); /* Cache size. */ { iInputWidget *cache = new_InputWidget(4); setSelectAllOnFocus_InputWidget(cache, iTrue); -- cgit v1.2.3