0

I'm canonicalizing URLs using Perl (v. 5.12) and I've noticed that the Perl program started crashing with the message "Identifier too long at (eval 1) line 1.". Through experiments I've found out that the URI constructor throws error when the scheme part of the URL exceeds 248 symbols:

$ perl -e 'use URI; my $uri = URI->new("a" x 248 . "://bla");'
Identifier too long at (eval 1) line 1.

Why is this happening? How to prevent this?

4

1 回答 1

4

URI正在寻找一个名为

URI::aaaaaaaaaa

通过做归结为

eval "require URI::aaaaaaaaaa;"

Perl 认为你疯了。

>perl -e"eval 'require '.('a' x 500); die $@;"
Identifier too long at (eval 1) line 1.

最好的解决方案是向作者提交补丁以添加

return if length($scheme) > 200;

implementor.


同时,您可以使用捕获错误

my $uri = eval { URI->new( ... ) };

或者您可以预先检查该条件:

$uri_string =~ /^${URI::scheme_re}:/
于 2013-03-05T19:06:10.160 回答