Skip to content

Commit 1da1bdb

Browse files
Merge pull request #194 from jviide/turbo-entities
Add encodeEntities fast path for inputs that don't need anything replaced
2 parents d1a9ddd + 9f09ba1 commit 1da1bdb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/util.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
// DOM properties that should NOT have "px" added when numeric
22
export const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i;
33

4-
export function encodeEntities(s) {
5-
return String(s)
4+
const ENCODED_ENTITIES = /[&<>"]/;
5+
6+
export function encodeEntities(input) {
7+
const s = String(input);
8+
if (!ENCODED_ENTITIES.test(s)) {
9+
return s;
10+
}
11+
return s
612
.replace(/&/g, '&amp;')
713
.replace(/</g, '&lt;')
814
.replace(/>/g, '&gt;')

0 commit comments

Comments
 (0)