bevacqua/insane

Different output at node and at browser

Opened this issue · 3 comments

simple example

const insane = require('insane');
console.log(insane('<a href="&#106;">test</a>'));

Running this under node gives <a href="j">test</a> see https://repl.it/repls/CloseMassiveArchitects
And running this under browser gives <a href="&amp;#106;">test</a> see https://codesandbox.io/s/k3ql74k5y5

This causes an issues with server side rendering.

The issue is that for browser used escape/unescapeHtml from ./she.js but he.decode/encode at node
@bevacqua what the reason to use 2 different method of conversion depending on env?

I just checked and in both cases sanitize-html uses decode/encode so both output of above is <a href="j">test</a>

I think you did that to reduce dependency size at browser level? If yes it's possibly better to use she.js in both environments, otherwise it's hard to use the library with server side rendering libs like React. See #10