Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81152 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule escapeTextForBrowser
10
* @typechecks static-only
11
*/
12
13
"use strict";
14
15
var ESCAPE_LOOKUP = {
16
"&": "&",
17
">": ">",
18
"<": "&lt;",
19
"\"": "&quot;",
20
"'": "&#x27;"
21
};
22
23
var ESCAPE_REGEX = /[&><"']/g;
24
25
function escaper(match) {
26
return ESCAPE_LOOKUP[match];
27
}
28
29
/**
30
* Escapes text to prevent scripting attacks.
31
*
32
* @param {*} text Text value to escape.
33
* @return {string} An escaped string.
34
*/
35
function escapeTextForBrowser(text) {
36
return ('' + text).replace(ESCAPE_REGEX, escaper);
37
}
38
39
module.exports = escapeTextForBrowser;
40
41