Fix hashtag parsing
Changelog-Fixed: No longer parse hashtags in urls Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -132,6 +132,19 @@ func is_hashtag_char(_ c: Character) -> Bool {
|
||||
return c.isLetter || c.isNumber
|
||||
}
|
||||
|
||||
func prev_char(_ p: Parser, n: Int) -> Character? {
|
||||
if p.pos - n < 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
let ind = p.str.index(p.str.startIndex, offsetBy: p.pos - n)
|
||||
return p.str[ind]
|
||||
}
|
||||
|
||||
func is_punctuation(_ c: Character) -> Bool {
|
||||
return c.isWhitespace || c.isPunctuation
|
||||
}
|
||||
|
||||
func parse_hashtag(_ p: Parser) -> String? {
|
||||
let start = p.pos
|
||||
|
||||
@@ -139,6 +152,13 @@ func parse_hashtag(_ p: Parser) -> String? {
|
||||
return nil
|
||||
}
|
||||
|
||||
if let prev = prev_char(p, n: 2) {
|
||||
// we don't allow adjacent hashtags
|
||||
if !is_punctuation(prev) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
guard let str = parse_while(p, match: is_hashtag_char) else {
|
||||
p.pos = start
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user