react-native-render-html icon indicating copy to clipboard operation
react-native-render-html copied to clipboard

Unexpected behavior with strings containing ampersand character &

Open Tobi696 opened this issue 9 months ago • 2 comments

Decision Table

  • [x] My issue does not look like “The HTML attribute 'xxx' is ignored” (unless we claim support for it)
  • [x] My issue does not look like “The HTML element <yyy> is not rendered”

Good Faith Declaration

  • [x] I have read the HELP document here: https://git.io/JBi6R
  • [x] I have read the CONTRIBUTING document here: https://git.io/JJ0Pg
  • [x] I have confirmed that this bug has not been reported yet

Description

I have noticed a strange behaviour that probably originates from the library trying to parse special characters in html (&, &lquote, ....), but failing to do so.

// Fails
<RenderHTML source={{ html: "&amp;" }} />

// Works
<RenderHTML source={{ html: "&" }} />

// Fails
<RenderHTML source={{ html: "& " }} />

// Works
<RenderHTML source={{ html: " &" }} />
```

### React Native Information

```sh
don't know what to provide here
```

### RNRH Version

6.3.4

### Tested Platforms

- [ ] Android
- [x] iOS
- [ ] Web
- [ ] MacOS
- [ ] Windows

### Reproduction Platforms

- [ ] Android
- [x] iOS
- [ ] Web
- [ ] MacOS
- [ ] Windows

### Minimal, Reproducible Example

// Fails <RenderHTML source={{ html: "&" }} />

// Works <RenderHTML source={{ html: "&" }} />

// Fails <RenderHTML source={{ html: "& " }} />

// Works <RenderHTML source={{ html: " &" }} />


### Additional Notes

_No response_

Tobi696 avatar Apr 29 '25 16:04 Tobi696

I can confirm that this is also happening on Android with the test cases above. The HTML strings I have to deal with are littered with &nbsp; and &bull;.

This is using Expo 53 / RN 0.79.3 on the new arch.

jake-carpenter avatar Jun 11 '25 13:06 jake-carpenter

~~Good news. patching in an update to the htmlparser2 dependency seems to have solved it. I will do some testing in the simulator, emulator, and on devices with htmlparser2 8.0.2 and 10.0.0 and put up a PR if all goes well. For now, here's the patch I'm using:~~

Patching turned into a mess that only worked because I had installed htmlparser2 as my own dependency. I ended up adding an override to my package.json. Note that mine is for pnpm:

"pnpm": {
  "overrides": {
    "htmlparser2": "8.0.2"
  }
}

Ultimately, the issue is that @native-html/transient-render-engine needs to update the dependency on htmlparser2.

jake-carpenter avatar Jun 11 '25 15:06 jake-carpenter