styles are always removed in browser
See original GitHub issueTo Reproduce
It always happens in browserland. See this simple codesandbox:
https://codesandbox.io/s/festive-kirch-d1geou?file=/src/index.js
Original message is below but note this is not React-specific. -Tom
Original message
Step by step instructions to reproduce the behavior:
- Create React App React 17
- call this in first page
console.log(
'html sanitizeHtml',
sanitizeHtml('<p style="color:#c0392b">test</p>', {
allowedTags: sanitizeHtml.defaults.allowedTags.concat([
'iframe',
'img',
'del',
'ins',
]),
allowedStyles: {
p: {
// Match HEX and RGB
color: [
/^.*$/i,
/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/,
],
},
},
allowedAttributes: {
'*': ['style'],
},
})
);
Expected behavior
<p style="color:#c0392b">test</p>
What i get
<p>test</p>
Describe the bug
the style attribute was removed
Details
"dependencies": {
"@emotion/react": "^11.4.1",
"@emotion/styled": "^11.6.0",
"@mui/icons-material": "^5.4.1",
"@mui/lab": "^5.0.0-alpha.71",
"@mui/material": "^5.4.1",
"@mui/styled-engine-sc": "^5.4.1",
"@mui/x-data-grid": "^5.5.0",
"date-fns": "^2.28.0",
"froala-editor": "^4.0.9",
"i18next": "^21.6.11",
"react": "^17.0.2",
"react-beautiful-dnd": "^13.1.0",
"react-device-detect": "^2.1.2",
"react-dom": "^17.0.2",
"react-fast-compare": "^3.2.0",
"react-froala-wysiwyg": "^4.0.9",
"react-hook-form": "^7.26.1",
"react-i18next": "^11.15.4",
"react-router-dom": "^5.3.0",
"react-router-hash-link": "^2.4.3",
"sanitize-html": "^2.7.0",
"sort-json": "^2.0.0"
},
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:21 (6 by maintainers)
Top Results From Across the Web
Website still shows styles that are removed from css file?
I added different styles but the same background color was persistent. Finally I completely deleted the actual css file from my hard drive, ......
Read more >How to Disable Website CSS Style (Chrome, Firefox, Edge, ...)
1. Disable CSS Style Using Browser Extension (Chrome, Firefox) · Navigate to the extension location (Chrome – Firefox), install and activate it. ·...
Read more >Remove "Page Styles" Browser Extension Virus - MalwareTips
This guide teaches you how to remove the "Page Styles" browser extension virus by following easy step-by-step instructions.
Read more >How to remove browser styles and why you need to reset CSS ...
Any browser adds its own CSS styles to almost all elements. How can I undo them and reset the CSS, and do I...
Read more >Avoid Default Browser Focus Styles - Adrian Roselli
This is particularly problematic when in-content links (in particular) are the same color as the surrounding text and/or have no underlines.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same here. Please, can someone look into this - kind of a blocker for using this package in the browser
They’re not wrong (: We have always felt that the use of sanitize-html on the browser side is a little bit crazy, since you can never trust a browser anyway, although I accept there’s an edge case where you use it for output of otherwise untrusted input… even though that is unnecessary overhead… on every single render! Sanitization and servers go together like bread and jam.