Add js lib function for escaping HTML

This commit is contained in:
graham-dds
2020-01-07 15:25:55 -05:00
parent b1d4d62533
commit eaa6b33b8e
2 changed files with 41 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
import escape from '../escape'
describe('escape', () => {
const htmlEscapes = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
'/': '&#x2F;',
}
it('should escape each character', () => {
for (let [char, escapedChar] of Object.entries(htmlEscapes)) {
expect(escape(char)).toBe(escapedChar)
}
})
it('should escape multiple characters', () => {
expect(escape('& and < and > and " and \' and /')).toBe(
'&amp; and &lt; and &gt; and &quot; and &#x27; and &#x2F;'
)
})
})