Browse Source

Fix when calling parse_hex_char out of bounds

Closes: #158
Changelog-Fixed: Fix crash with @ sign in some posts
post-button-style
Pablo Fernandez 2 years ago
committed by William Casarin
parent
commit
205774f684
  1. 6
      damus/Util/Parser.swift
  2. 8
      damusTests/ReplyTests.swift

6
damus/Util/Parser.swift

@ -97,6 +97,12 @@ func parse_digit(_ p: Parser) -> Int? {
func parse_hex_char(_ p: Parser) -> Character? { func parse_hex_char(_ p: Parser) -> Character? {
let ind = p.str.index(p.str.startIndex, offsetBy: p.pos) let ind = p.str.index(p.str.startIndex, offsetBy: p.pos)
// Check that we're within the bounds of p.str's length
if p.pos >= p.str.count {
return nil
}
if let c = p.str[ind].unicodeScalars.first { if let c = p.str[ind].unicodeScalars.first {
// hex chars // hex chars
let d = c.value let d = c.value

8
damusTests/ReplyTests.swift

@ -53,6 +53,14 @@ class ReplyTests: XCTestCase {
XCTAssertEqual(blocks[0].is_text, content) XCTAssertEqual(blocks[0].is_text, content)
} }
func testAtAtEnd() {
let content = "what @"
let blocks = parse_post_blocks(content: content)
XCTAssertEqual(blocks.count, 1)
XCTAssertEqual(blocks[0].is_text, "what @")
}
func testHashtagsInQuote() { func testHashtagsInQuote() {
let content = "This is my \"#awesome post\"" let content = "This is my \"#awesome post\""
let blocks = parse_post_blocks(content: content) let blocks = parse_post_blocks(content: content)

Loading…
Cancel
Save