gpt4 book ai didi

javascript - 正则表达式中的 JSLint "insecure ^"

转载 作者:行者123 更新时间:2023-12-04 19:35:23 25 4
gpt4 key购买 nike

JSLint 报告以下行的不安全“^”。这是为什么?还是只要我想否定一个字符类,它就会提示?

// remove all non alphanumeric, comma and dash characters
"!$7s-gd,&j5d-a#".replace(/[^\w,\-]/g, '');

最佳答案

只有在底部选择了选项时才会执行此操作:

Disallow insecure . and [^...] in /RegExp/

来自 the docs :

true if . and [^...] should not be allowed in RegExp literals. These forms should not be used when validating in secure applications.

所以回答你的问题,如果你用 ^ 开始一个正则表达式并且它被选中,是的,它每次都会抛出错误。问题在于 unicode 字符,您几乎允许其中的任何内容,并且可能存在安全问题或验证绕过问题。而不是禁止某些东西(可以绕过),只允许哪些字符是有效的。

关于javascript - 正则表达式中的 JSLint "insecure ^",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15937618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com