commit 13ea42a2e26e2e6b2015e251f4122d6ee539c432
parent d9e22ce7bf21ca625ed9c60612de26a4ffd31e2c
Author: Joel Klabo <joelklabo@gmail.com>
Date: Fri, 20 Jan 2023 20:49:58 -0800
Don't Parse URL with Only Whitespace
Diffstat:
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/damus-c/damus.c b/damus-c/damus.c
@@ -31,14 +31,16 @@ static void make_cursor(struct cursor *c, const u8 *content, size_t len)
static int consume_until_whitespace(struct cursor *cur, int or_end) {
char c;
+ bool consumedAtLeastOne = false;
while (cur->p < cur->end) {
c = *cur->p;
- if (is_whitespace(c))
+ if (is_whitespace(c) && consumedAtLeastOne)
return 1;
cur->p++;
+ consumedAtLeastOne = true;
}
return or_end;
diff --git a/damusTests/damusTests.swift b/damusTests/damusTests.swift
@@ -105,6 +105,14 @@ class damusTests: XCTestCase {
XCTAssertEqual(parsed[1].is_text, " br")
}
+ func testNoParseUrlWithOnlyWhitespace() {
+ let testString = "https:// "
+ let parsed = parse_mentions(content: testString, tags: [])
+
+ XCTAssertNotNil(parsed)
+ XCTAssertEqual(parsed[0].is_text, testString)
+ }
+
func testParseMentionBlank() {
let parsed = parse_mentions(content: "", tags: [["e", "event_id"]])