diff --git a/damus-c/cursor.h b/damus-c/cursor.h index 78aca7fb..69e88eae 100644 --- 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 index f9fa09ac..ad1bf725 100644 --- 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...) {