转义输入但识别有效的网络链接

问题描述

我有一个聊天应用程序,我用它来逃避/清理用户输入,

2021-02-06T04:31:53.538645+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/api/recipes" host=shielded-lake-68439.herokuapp.com request_id=75fe735e-cf8a-4ff6-a478-e8495a0ff918 fwd="76.18.97.75" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https

但我仍然想使用它,以便用户可以在聊天中发布可点击的链接

function sanitize(string) {
  const map = {
      '&': '&amp;','<': '&lt;','>': '&gt;','"': '&quot;',"'": '&#x27;',"/": '&#x2F;',"`": '&grave;',};
  const reg = /[&<>"'/]/ig;
  return string.replace(reg,(match)=>(map[match]));
}

有没有办法用第一个函数清理并仍然显示与第二个函数链接

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)