Skip to content

Commit

Permalink
Move skipping invalid ranges to parser on iOS (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw authored Dec 5, 2024
1 parent 9a7971d commit 6a85ff5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 4 additions & 0 deletions apple/MarkdownParser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ @implementation MarkdownParser {
const auto &length = static_cast<int>(item.getProperty(rt, "length").asNumber());
const auto &depth = item.hasProperty(rt, "depth") ? static_cast<int>(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];
Expand Down
4 changes: 0 additions & 4 deletions apple/RCTMarkdownUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 6a85ff5

Please sign in to comment.