Commit 6979b31
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1384 | 1384 | | |
1385 | 1385 | | |
1386 | 1386 | | |
1387 | | - | |
1388 | | - | |
1389 | | - | |
1390 | | - | |
1391 | | - | |
1392 | | - | |
1393 | | - | |
1394 | | - | |
1395 | | - | |
1396 | | - | |
1397 | | - | |
1398 | | - | |
1399 | | - | |
1400 | | - | |
1401 | | - | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
1402 | 1399 | | |
1403 | 1400 | | |
1404 | 1401 | | |
| |||
0 commit comments