Ruby: URI::InvalidURIError (URI must be ascii only

前端 未结 3 1945
抹茶落季
抹茶落季 2021-01-07 17:57
require \'uri\'
uri = URI.parse \'http://dxczjjuegupb.cloudfront.net/wp-content/uploads/2017/10/Оуэн-Мэтьюс.jpg\'

The browsers have no problem with

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-07 18:22

    The answer just came to me by asking myself the question:

    begin
      uri = URI.parse(url)
    rescue URI::InvalidURIError
      uri = URI.parse(URI.escape(url))
    end
    

提交回复
热议问题