Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trimEnd 相关 #6

Open
xovel opened this issue Jun 14, 2019 · 1 comment
Open

trimEnd 相关 #6

xovel opened this issue Jun 14, 2019 · 1 comment

Comments

@xovel
Copy link
Owner

xovel commented Jun 14, 2019

听说有一个操作,叫做 REDOS,形如 /c*$/ 的正则构造可能会导致 REDOS,吓得我赶紧写了一个方法做为替代:

// trimEnd by token without regular expression
// /c*$/ is vulnerable to REDOS. ??
function _trimEnd(text, token) {
  while (text && token && text.substring(text.length - token.length) === token) {
    text = text.substring(0, text.length - token.length)
  }
  return text
}
@xovel
Copy link
Owner Author

xovel commented Jun 14, 2019

缺点也很明显了,就是不支持正则匹配,只能定向去除指定的拖尾字符串或者字符串。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant