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>
This commit is contained in:
kernelkind 2024-01-01 15:17:13 -05:00 committed by William Casarin
parent 40134b4365
commit 692146fe00
2 changed files with 46 additions and 1 deletions

View File

@ -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){

View File

@ -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...) {