commit 3e880dbd7111257a8695f735672ac3cbe078d10a
parent 8e35b8507e4f2ff8b58134b95669c99b2f2966ca
Author: Andrew Laack <andrew@laack.co>
Date: Mon, 28 Sep 2026 10:37:32 -0500
Handle special format characters correctly.
Diffstat:
7 files changed, 99 insertions(+), 6 deletions(-)
diff --git a/TODO.txt b/TODO.txt
@@ -94,11 +94,13 @@
---
-- gemini://m0yng.uk/2020/10/A-simple-hit-counter/
- - something is fucking up that site; seems like trailing ^M characters I see in vim
- - what are those?
-- this is messed up too:
- - gemini://supernovas.space/gemlog/2023-08-19-gemini-page-counter.gmi
+ISSUES:
+
+- gemini://bbs.geminispace.org/u/dragfyre
+ - first link is:
+ - [1] gemini://broken-link.com
+ - but should be:
+ - https://mastodon.sandwich.net/@dragfyre
---
diff --git a/include/utils.hpp b/include/utils.hpp
@@ -43,3 +43,6 @@ struct Destination {
};
Destination handleDestinationResolution(std::string destination, bool isCli);
+
+
+void sanitizeCharactersToDraw(std::vector<std::pair<std::string, TextRender>>& strLs);
diff --git a/src/main.cpp b/src/main.cpp
@@ -2,6 +2,7 @@
#include "../include/utils.hpp"
#include <algorithm>
#include <cassert>
+#include <cctype>
#include <chrono>
#include <cstdint>
#include <ncurses.h>
@@ -34,6 +35,7 @@ void initColors() {
}
}
}
+
struct DrawState {
std::vector<std::pair<std::string, TextRender>> prior;
Browser* bPtr;
@@ -117,10 +119,15 @@ void draw(DrawState& ds) {
if(cs != nullptr && (cs->getStatusCode() < 20 || cs->getStatusCode() > 29)) {
current = ds.prior;
+ current = breakLines(current,std::min(COLS, maxWidth), COLS);
+ sanitizeCharactersToDraw(current);
} else {
+
current = ds.bPtr->renderSite();
current = breakLines(current,std::min(COLS, maxWidth), COLS);
+ sanitizeCharactersToDraw(current);
+
ds.prior = current;
}
diff --git a/src/utils.cpp b/src/utils.cpp
@@ -403,3 +403,24 @@ Destination handleDestinationResolution(std::string destination, bool isCli) {
}
throw std::logic_error("Unexpected input.");
}
+
+// TODO: Should this be part of the rendering step for the browser or should this remain as post-processing?
+void sanitizeCharactersToDraw(std::vector<std::pair<std::string, TextRender>>& strLs) {
+ for(std::size_t i = 0; i < strLs.size(); ++i) {
+
+ std::string& s = strLs[i].first;
+
+ std::string out;
+ for (int c: s)
+ if (c == '\r' || c == '\v' || c == '\b' || c == '\f' || c == '\a' || c == '\0') {
+ continue;
+ } else if (c == '\t') {
+ out += " "; // \t is a larger character and fucks with breaklines.
+ } else {
+ out += c;
+ }
+
+ strLs[i].first = out;
+ }
+ return;
+}
diff --git a/tests/browser-test.cpp b/tests/browser-test.cpp
@@ -81,3 +81,18 @@ TEST_CASE("Test encoding allows relative linking with : in parameter") {
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search?https%3A%2F%2Ftest.com");
}
+
+
+
+
+TEST_CASE("Sanitize characters to draw tests") {
+ Browser b {};
+ bool res = b.goToSite("file:///home/andrew/gitRepos/gemini-browser/tests/sites/line-return.gmi");
+ REQUIRE(res);
+ auto ls = b.renderSite();
+ sanitizeCharactersToDraw(ls);
+ for(auto& line : ls) {
+ REQUIRE(line.first.find('\r') == std::string::npos);
+ }
+}
+
diff --git a/tests/pure-test.cpp b/tests/pure-test.cpp
@@ -277,4 +277,3 @@ TEST_CASE("Crash test rng") {
}
}
-
diff --git a/tests/sites/line-return.gmi b/tests/sites/line-return.gmi
@@ -0,0 +1,46 @@
+
+# đĒ Hidden Nexus
+A social place in Gemspace!
+
+=> /register/ đą Register
+=> /feed đ Just Browsing!
+
+
+### What is the Hidden Nexus?
+The Hidden Nexus is a place in Gemspace that allows capsuleers, Geminauts, and other explorers of Gemspace to collaborate and communicate together. It was designed from the beginning to provide a clean UI with granular settings to customize the user experience to ones needs.
+
+
Register if you would like, or just browse the existing feed!
+
Established 2023-08-24, we are currently home to 53 registered users!
+
+
With a friendly user experience, powerful settings, and many planned features, it speaks for itself.
+
+
+## đ° News
+
+### 2026-01-15
+=> gemini://hidden.nexus/gcl/content/ Gemini Capsule Library released!
+----------------
+Hidden Nexus' dynamic forms and interactivity have been enabled by a project I've made called Gemini Capsule Library!
+This Python library allows for easy creation of dynamic forms, as well as the ability to extend functionality to create things such as account registration.
+
+If anyone has any questions on how to use this project, please feel free to email me or post about it!
+----------------
+### 2023-08-23
+=> /captchasubmission/ We're looking for more knowledge questions!
+----------------
+As you've seen when registering, you're asked a kind of captcha from a list of question/answer pairs.
+I've tasked myself and friends with thinking of the ones currently being used, but I would like to ask anyone to contribute!
+
+Registered users can click on title of this news bulletin and submit a question answer pair!
+These can be any kind of question category (logic, math, reading comprehention, etc.) as long as they are relatively ACCESSIBLE. In the style of the existing pairs.
+
+I'll go through them and add ones I like to the database of question/answer pairs!
+----------------
+
+
+
+
+=> /register/ Register
+----------------
+=> mailto:abraxas@hidden.nexus Contact
+=> /about.gmi âšī¸ About