Add js lib function for escaping HTML
This commit is contained in:
21
js/lib/__tests__/escape.test.js
Normal file
21
js/lib/__tests__/escape.test.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import escape from '../escape'
|
||||
describe('escape', () => {
|
||||
const htmlEscapes = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
'/': '/',
|
||||
}
|
||||
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(
|
||||
'& and < and > and " and ' and /'
|
||||
)
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user