diff --git a/apple/MarkdownParser.mm b/apple/MarkdownParser.mm index c9f3d018..739f106d 100644 --- a/apple/MarkdownParser.mm +++ b/apple/MarkdownParser.mm @@ -46,6 +46,10 @@ @implementation MarkdownParser { const auto &length = static_cast(item.getProperty(rt, "length").asNumber()); const auto &depth = item.hasProperty(rt, "depth") ? static_cast(item.getProperty(rt, "depth").asNumber()) : 1; + if (length == 0 || start + length > text.length) { + continue; + } + NSRange range = NSMakeRange(start, length); MarkdownRange *markdownRange = [[MarkdownRange alloc] initWithType:@(type.c_str()) range:range depth:depth]; [markdownRanges addObject:markdownRange]; diff --git a/apple/RCTMarkdownUtils.mm b/apple/RCTMarkdownUtils.mm index 11a20bca..57d90774 100644 --- a/apple/RCTMarkdownUtils.mm +++ b/apple/RCTMarkdownUtils.mm @@ -70,10 +70,6 @@ - (NSAttributedString *)parseMarkdown:(nullable NSAttributedString *)input withA } - (void)applyRangeToAttributedString:(NSMutableAttributedString *)attributedString type:(const std::string)type range:(NSRange)range depth:(const int)depth { - if (range.length == 0 || range.location + range.length > attributedString.length) { - return; - } - if (type == "bold" || type == "italic" || type == "code" || type == "pre" || type == "h1" || type == "emoji") { UIFont *font = [attributedString attribute:NSFontAttributeName atIndex:range.location effectiveRange:NULL]; if (type == "bold") {