我想要验证的无效网址无效,但Ruby的URI说它有效:
url = "https://blah.%20wordpress.com/"
# => "https://blah.%20wordpress.com/"
url =~ URI::DEFAULT_PARSER.regexp[:ABS_URI]
# => 0
我有办法确认它无效吗?
答案 0 :(得分:2)
尝试URI::DEFAULT_PARSER.regexp[:UNSAFE]
url = "https://blah.%20wordpress.com/"
url =~ URI::DEFAULT_PARSER.regexp[:UNSAFE]
# => 13
safe_url = "https://blah.wordpress.com/"
safe_url =~ URI::DEFAULT_PARSER.regexp[:UNSAFE]
# => nil