Skip to content

Commit 6979b31

Browse files
authored
fix(iOS): redundant check in headings parsing (#479)
# Summary On iOS, `react-native-enriched` can crash when pasting text copied from the ChatGPT app into `EnrichedTextInput`. The ChatGPT app places full HTML on the pasteboard, including a `<head>` section. In the iOS parser, heading detection was too broad and treated any tag starting with `h` as a heading candidate. That causes `<head>` to enter the heading branch even though only `h1`-`h6` are supported. As a result, the parser builds malformed style data and later crashes with: ```text NSRangeException: *** -[__NSArrayM objectAtIndexedSubscript:]: index 1 beyond bounds [0 .. 0] ``` **Root Cause** The iOS parser matched tags by checking whether the tag name started with `h`, instead of matching only supported heading tags. Because of that, `<head>` was treated like a heading-related tag, which produced an invalid parsed style entry and caused the crash later in processing. **Fix** Restrict heading handling on iOS to exact matches for `h1`, `h2`, `h3`, `h4`, `h5`, and `h6` only. This prevents `<head>` and other unrelated `h*` tags from being misclassified. ## Test Plan 1. Copy formatted text from the ChatGPT iOS (or macOS) app. 2. Paste it into `EnrichedTextInput` on iOS. 3. The app crashes during HTML parsing. **Example clipboard HTML from ChatGPT** ```html <html> <head> <meta charset="UTF-8"> </head> <body> <p class="p1">Some text</p> </body> </html> ``` ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ✅ |
1 parent 40c80af commit 6979b31

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

ios/inputParser/InputParser.mm

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,21 +1384,18 @@ - (NSArray *)getTextAndStylesFromHtml:(NSString *)fixedHtml {
13841384
mentionParams.attributes = formattedAttrsString;
13851385

13861386
stylePair.styleValue = mentionParams;
1387-
} else if ([[tagName substringWithRange:NSMakeRange(0, 1)]
1388-
isEqualToString:@"h"]) {
1389-
if ([tagName isEqualToString:@"h1"]) {
1390-
[styleArr addObject:@([H1Style getStyleType])];
1391-
} else if ([tagName isEqualToString:@"h2"]) {
1392-
[styleArr addObject:@([H2Style getStyleType])];
1393-
} else if ([tagName isEqualToString:@"h3"]) {
1394-
[styleArr addObject:@([H3Style getStyleType])];
1395-
} else if ([tagName isEqualToString:@"h4"]) {
1396-
[styleArr addObject:@([H4Style getStyleType])];
1397-
} else if ([tagName isEqualToString:@"h5"]) {
1398-
[styleArr addObject:@([H5Style getStyleType])];
1399-
} else if ([tagName isEqualToString:@"h6"]) {
1400-
[styleArr addObject:@([H6Style getStyleType])];
1401-
}
1387+
} else if ([tagName isEqualToString:@"h1"]) {
1388+
[styleArr addObject:@([H1Style getStyleType])];
1389+
} else if ([tagName isEqualToString:@"h2"]) {
1390+
[styleArr addObject:@([H2Style getStyleType])];
1391+
} else if ([tagName isEqualToString:@"h3"]) {
1392+
[styleArr addObject:@([H3Style getStyleType])];
1393+
} else if ([tagName isEqualToString:@"h4"]) {
1394+
[styleArr addObject:@([H4Style getStyleType])];
1395+
} else if ([tagName isEqualToString:@"h5"]) {
1396+
[styleArr addObject:@([H5Style getStyleType])];
1397+
} else if ([tagName isEqualToString:@"h6"]) {
1398+
[styleArr addObject:@([H6Style getStyleType])];
14021399
} else if ([tagName isEqualToString:@"ul"]) {
14031400
if ([self isUlCheckboxList:params]) {
14041401
[styleArr addObject:@([CheckboxListStyle getStyleType])];

0 commit comments

Comments
 (0)