main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
971 bytes
|
Rev | Line | |
---|
[d565449] | 1 | /**
|
---|
| 2 | * @fileoverview XML character escaper
|
---|
| 3 | * @author George Chung
|
---|
| 4 | */
|
---|
| 5 | "use strict";
|
---|
| 6 |
|
---|
| 7 | //------------------------------------------------------------------------------
|
---|
| 8 | // Public Interface
|
---|
| 9 | //------------------------------------------------------------------------------
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | * Returns the escaped value for a character
|
---|
| 13 | * @param {string} s string to examine
|
---|
| 14 | * @returns {string} severity level
|
---|
| 15 | * @private
|
---|
| 16 | */
|
---|
| 17 | module.exports = function(s) {
|
---|
| 18 | return (`${s}`).replace(/[<>&"'\x00-\x1F\x7F\u0080-\uFFFF]/gu, c => { // eslint-disable-line no-control-regex -- Converting controls to entities
|
---|
| 19 | switch (c) {
|
---|
| 20 | case "<":
|
---|
| 21 | return "<";
|
---|
| 22 | case ">":
|
---|
| 23 | return ">";
|
---|
| 24 | case "&":
|
---|
| 25 | return "&";
|
---|
| 26 | case "\"":
|
---|
| 27 | return """;
|
---|
| 28 | case "'":
|
---|
| 29 | return "'";
|
---|
| 30 | default:
|
---|
| 31 | return `&#${c.charCodeAt(0)};`;
|
---|
| 32 | }
|
---|
| 33 | });
|
---|
| 34 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.