如何解决SonarQube-不应使用函数构造函数
我将SonarQube扫描用于ASP.NET MVC项目以进行代码质量检查。 SonarQube显示了项目中使用的一个JavaScript库的漏洞错误。 即-datepicker.js
错误- 查看此“函数”调用,并确保其参数已正确验证。
下面是datepicker.js中的代码-
(function(){
var cache = {};
this.tmpl = function tmpl(str,data){
// Figure out if we're getting a template,or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :
// Generate a reusable function that will serve as a template
// generator (and which will be cached).
new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};" +
// Introduce the data as local variables using with(){}
"with(obj){p.push('" +
// Convert the template into pure JavaScript
str
.replace(/[\r\t\n]/g," ")
.split("<%").join("\t")
.replace(/((^|%>)[^\t]*)'/g,"$1\r")
.replace(/\t=(.*?)%>/g,"',$1,'")
.split("\t").join("');")
.split("%>").join("p.push('")
.split("\r").join("\\'")
+ "');}return p.join('');");
// Provide some basic currying to the user
return data ? fn( data ) : fn;
};
})
此处显示了所用函数构造函数的漏洞-
new Function("obj",arguments);};" +
// Introduce the data as local variables using with(){}
解决方案-它也提供了解决方案。它说,您应该使用ECMAScript 5的内置JSON函数或专用库。
链接-https://rules.sonarsource.com/javascript/RSPEC-3523
哪些替代方法可以代替新功能(“ param1”,“ param2”)通过声纳扫描?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。