commit 555fd8d749b0db5f01f9fca70fed31ec3ead6b0c
parent 4c76bbf57903774dfdd3dfa5733dcbf5dae2797d
Author: Andrew Laack <andrew@laack.co>
Date: Sun, 4 Oct 2026 12:12:48 -0500
Support localhost
Diffstat:
4 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/POSSIBLE_CHANGES.txt b/POSSIBLE_CHANGES.txt
@@ -9,3 +9,4 @@
- right now we just truncate, which is good enough for general usage: if you want more, use gemget.
- url manipulation
- sometimes it's nice to go from {example}.com/blog/whatever -> {example}.com/blog without having to find links.
+- issue text should perhaps replace the url for a bit?
diff --git a/TODO.txt b/TODO.txt
@@ -1,5 +1,3 @@
-- localhost access
- - localhost:1965 broken
- cleanups
- function signatures (const, noexcept)
- types
diff --git a/src/utils.cpp b/src/utils.cpp
@@ -377,7 +377,7 @@ Destination handleDestinationResolution(std::string destination, bool isCli) {
try {
std::size_t pos = 0;
int dest = std::stoi(destination,&pos);
- if(pos == destination.size() && dest >= 0) { // overflow or not full conversion
+ if(pos == destination.size() && dest >= 0) {
ret.linkNumber = dest;
ret.t = NUMBER_DESTINATION;
return ret;
@@ -385,13 +385,18 @@ Destination handleDestinationResolution(std::string destination, bool isCli) {
throw std::invalid_argument("Unable to convert fully");
}
} catch (...) {
- if(destination.find(":") == std::string::npos || destination.find(' ') != std::string::npos) {
+
+ if (destination.find(' ') == std::string::npos && (destination.rfind("localhost:", 0) == 0 || destination.rfind("localhost/", 0) == 0 || destination == "localhost")) {
+ destination = "gemini://" + destination;
+ }
+ else if(destination.find("://") == std::string::npos || destination.find(' ') != std::string::npos) {
if(destination.find('.') != std::string::npos && destination.find(' ') == std::string::npos) {
destination = "gemini://" + destination;
} else {
destination = DEFAULT_SEARCH_ENGINE + urlEncode(destination);
}
}
+
ret.destination = destination;
ret.t = STRING_DESTINATION;
return ret;
diff --git a/tests/pure-test.cpp b/tests/pure-test.cpp
@@ -23,6 +23,7 @@ TEST_CASE("Test cli input handling") {
expectations["gopher://github.com"] = "gopher://github.com";
expectations["gemini://github.com"] = "gemini://github.com";
expectations["file:///home/whatever"] = "file:///home/whatever";
+ expectations["localhost"] = "gemini://localhost";
for(auto& expect : expectations) {
REQUIRE(handleDestinationResolution(expect.first, true).destination == expect.second);
REQUIRE(handleDestinationResolution(expect.first, true).t == STRING_DESTINATION);
@@ -107,6 +108,14 @@ TEST_CASE("Test user input handling for destinations") {
REQUIRE(handleDestinationResolution("laack.co", false).destination == "gemini://laack.co");
}
+ SECTION("Support localhost") {
+ REQUIRE(handleDestinationResolution("localhost", false).destination == "gemini://localhost");
+ REQUIRE(handleDestinationResolution("gemini://localhost", false).destination == "gemini://localhost");
+ REQUIRE(handleDestinationResolution("gemini://localhost:1965", false).destination == "gemini://localhost:1965");
+ REQUIRE(handleDestinationResolution("localhost:1965", false).destination == "gemini://localhost:1965");
+
+ }
+
SECTION("Transparently resolve file names") {
REQUIRE(handleDestinationResolution("file:///test/whatever", false).t == STRING_DESTINATION);
REQUIRE(handleDestinationResolution("file:///test/whatever", false).destination == "file:///test/whatever");