apostrophecms / sanitize-html

Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis. Built on htmlparser2 for speed and tolerance
MIT License
3.84k stars 353 forks source link

Add option to remove warning #613

Closed mog422 closed 1 year ago

mog422 commented 1 year ago

The problem to solve

https://github.com/apostrophecms/sanitize-html/blob/25869acb40033803f2c337d7bc6fbf628a030fd9/index.js#L454

Even when normally using check arbitrary user input on the server side, Log spam occurs whenever user inputs an invalid style.

Proposed solution

Add option to remove warning

Alternatives

Only print warning whe actually running in the browser environment.

Additional context

boutell commented 1 year ago

I agree this is not great. Fortunately it is easy to detect the browser. Would you like to send a PR?

boutell commented 1 year ago
if (typeof window === 'undefined')
// this is node

I think this is safer than checking the other way around because it would be nice not to break alternatives to Node.

mog422 commented 1 year ago

I sent PR