commit 692146fe00ca0acdb8bb530cc1709410c8244b6e
parent 40134b4365abd5d2c33f473d6ebf7ba4a0b82af9
Author: kernelkind <kernelkind@gmail.com>
Date: Mon, 1 Jan 2024 15:17:13 -0500
add comma as disallowed char at end of url
Do not include comma as part of a URL if it is followed by whitespace.
This allows users to make lists of URLs.
Closes: https://github.com/damus-io/damus/issues/1833
LNURL1DP68GURN8GHJ7EM9W3SKCCNE9E3K7MF0D3H82UNVWQHKWUN9V4HXGCTHDC6RZVGR8SW3G
Signed-off-by: kernelkind <kernelkind@gmail.com>
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/damus-c/cursor.h b/damus-c/cursor.h
@@ -498,7 +498,7 @@ static inline int next_char_is_whitespace(unsigned char *curChar, unsigned char
}
static int char_disallowed_at_end_url(char c){
- return c == '.';
+ return c == '.' || c == ',';
}
static inline int is_final_url_char(unsigned char *curChar, unsigned char *endChar){
diff --git a/damusTests/UrlTests.swift b/damusTests/UrlTests.swift
@@ -140,6 +140,51 @@ final class UrlTests: XCTestCase {
func testParseURL_OneURLEndPeriodSerachQuery_RemovesPeriod(){
testParseURL(inputURLString: "https://www.example.com/search?q=test+query.", expectedURLs: "https://www.example.com/search?q=test+query")
}
+
+ func testParseURL_OneURLEndComma_RemovesComma(){
+ testParseURL(inputURLString: "http://example.com,", expectedURLs: "http://example.com")
+ }
+
+ func testParseURL_OneURL_RemovesComma(){
+ testParseURL(inputURLString: "http://example.com/,test", expectedURLs: "http://example.com/,test")
+ }
+
+ func testParseURL_OneURLEndCommaAndSpaceSimple_RemovesComma(){
+ testParseURL(inputURLString: "http://example.com, ", expectedURLs: "http://example.com")
+ }
+
+ func testParseURL_OneURLEndCommaComplex_RemovesComma(){
+ testParseURL(inputURLString: "http://example.com/test,", expectedURLs: "http://example.com/test")
+ }
+
+ func testParseURL_TwoURLEndCommaSimple_RemovesCommas(){
+ testParseURL(inputURLString: "http://example.com, http://example.com,", expectedURLs: "http://example.com", "http://example.com")
+ }
+
+ func testParseURL_ThreeURLEndCommaSimple_RemovesCommas(){
+ testParseURL(inputURLString: "http://example.com, http://example.com, http://example.com,", expectedURLs: "http://example.com", "http://example.com", "http://example.com")
+ }
+
+ func testParseURL_TwoURLEndCommaFirstComplexSecondSimple_RemovesCommas(){
+ testParseURL(inputURLString: "http://example.com/test, http://example.com,", expectedURLs: "http://example.com/test", "http://example.com")
+ }
+
+ func testParseURL_TwoURLEndCommaFirstSimpleSecondComplex_RemovesCommas(){
+ testParseURL(inputURLString: "http://example.com, http://example.com/test,", expectedURLs: "http://example.com", "http://example.com/test")
+ }
+
+ func testParseURL_TwoURLEndCommaFirstComplexSecondComplex_RemovesCommas(){
+ testParseURL(inputURLString: "http://example.com/test, http://example.com/test,", expectedURLs: "http://example.com/test", "http://example.com/test")
+ }
+
+ func testParseURL_OneURLEndCommaSerachQuery_RemovesComma(){
+ testParseURL(inputURLString: "https://www.example.com/search?q=test+query,", expectedURLs: "https://www.example.com/search?q=test+query")
+ }
+
+ func testParseURL_TwoURLFirstSimpleSecondSimpleNoSpace_RemovesCommas(){
+ testParseURL(inputURLString: "http://example.com,http://example.com,",
+ expectedURLs: "http://example.com", "http://example.com")
+ }
}
func testParseURL(inputURLString: String, expectedURLs: String...) {