Phenomenon
When pasting content that contains HTML entities (<, >, &, etc.), the entities may be decoded to actual characters or preserved as entities inconsistently. This causes issues with special characters.
Reproduction example
- Copy text containing HTML entities (e.g.,
<div>) - Paste into contenteditable element
- Observe the DOM
Observed behavior
- Entities may be decoded:
<div>appears in DOM - Or entities may be preserved:
<div>in DOM - Behavior is inconsistent
- Special characters may be lost or changed
Expected behavior
- Entity handling should be consistent
- Or behavior should be predictable
- Special characters should be preserved correctly
- Encoding/decoding should be explicit
Browser Comparison
- Chrome/Edge: Entity handling inconsistent (this case)
- Firefox: Similar inconsistent behavior
- Safari: Entity handling varies
Notes and possible direction for workarounds
- Normalize entity encoding after paste
- Decode or encode entities explicitly
- Handle special characters carefully
- Document expected entity behavior