简体   繁体   English

如何在Perl中链接文本?

[英]How do I linkify text in Perl?

I have some text I want to linkify, which I can reasonably do with a regex (search for http/https or www) but I'm worried about XSS complications. 我有一些要链接的文本,可以使用正则表达式(搜索http / https或www)进行合理地链接,但是我担心XSS的复杂性。 What's a safe way to do this in Perl? 在Perl中执行此操作的安全方法是什么?

Exactly what do you mean by XSS complications? 究竟XSS并发症是什么意思? Are you only concerned with JavaScript or do URLs of the form http://example.com/command?type=delete;who=sam etc concern you as well? 您只关心JavaScript还是http://example.com/command?type=delete;who=sam等形式的URL也与您有关?

As for linkifying URLs, there will always be edge cases, but Text::Markdown worked pretty well on a variety of inputs when I tried it. 至于链接URL,总是会出现边缘情况,但是当我尝试使用Text :: Markdown进行各种输入时,效果很好。 You can use the urls method to preprocess the links. 您可以使用urls方法预处理链接。

See also Regexp::Common . 参见Regexp :: Common

我无法谈论XSS问题,但是URI :: Find可以让您查找文本中的所有URI,并将其转换为所需的任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM