Skip to content

Commit 7705acb

Browse files
committed
fix sonar 安全问题
1 parent 6fe4ca6 commit 7705acb

File tree

1 file changed

+0
-42
lines changed

1 file changed

+0
-42
lines changed

src/common/format/JSON.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -76,48 +76,6 @@ export default class JSONFormat extends Format {
7676
catch (e) {
7777
// Fall through if the regexp test fails.
7878
}
79-
} else try {
80-
/**
81-
* Parsing happens in three stages. In the first stage, we run the
82-
* text against a regular expression which looks for non-JSON
83-
* characters. We are especially concerned with '()' and 'new'
84-
* because they can cause invocation, and '=' because it can
85-
* cause mutation. But just to be safe, we will reject all
86-
* unexpected characters.
87-
*/
88-
if (/^[\],:{}\s]*$/.test(json.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
89-
90-
/**
91-
* In the second stage we use the eval function to compile the
92-
* text into a JavaScript structure. The '{' operator is
93-
* subject to a syntactic ambiguity in JavaScript - it can
94-
* begin a block or an object literal. We wrap the text in
95-
* parens to eliminate the ambiguity.
96-
*/
97-
object = eval('(' + json + ')');
98-
99-
/**
100-
* In the optional third stage, we recursively walk the new
101-
* structure, passing each name/value pair to a filter
102-
* function for possible transformation.
103-
*/
104-
if (typeof filter === 'function') {
105-
function walk(k, v) {
106-
if (v && typeof v === 'object') {
107-
for (var i in v) {
108-
if (v.hasOwnProperty(i)) {
109-
v[i] = walk(i, v[i]);
110-
}
111-
}
112-
}
113-
return filter(k, v);
114-
}
115-
116-
object = walk('', object);
117-
}
118-
}
119-
} catch (e) {
120-
// Fall through if the regexp test fails.
12179
}
12280

12381
if (this.keepData) {

0 commit comments

Comments
 (0)