Linkify 正在链接无效链接.为什么?有没有办法防止这种情况

Linkify is linking invalid links. Why? Is there an option to prevent this?

本文关键字:链接 情况 有没有 无效 为什么 Linkify      更新时间:2023-09-26

我正在使用Linkify:https://github.com/cowboy/javascript-linkify

问题是Linkify正在链接无效链接,例如:

有效

http://techcrunch.com/

无效

checkthisouthttp://techcrunch.com/

关于如何防止链接链接非链接的任何想法?鉴于 Linkify 已经过时,还有什么更好的选择吗?谢谢

Linkify https://github.com/cowboy/javascript-linkify 只测试 URL 方案是否与 [a-z''d.-]+:// 匹配。

这确实与您的两个示例相匹配:checkthisouthttp://techcrunch.com/http://techcrunch.com/ .

更改它很简单,以便将 URL 方案限制为仅设置列表(例如 httphttps 等)。通过将第 73 行ba-linkify.js SCHEME = "[a-z''d.-]+://",替换为仅与这些方案匹配的正则表达式。