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

前端 未结 3 1944
抹茶落季
抹茶落季 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:09

    What do you think about:

    url = URI.escape(url) unless url.ascii_only?
    URI.parse(url)
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-01-07 18:22

    I had the same error:

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

    with my code, but my bug was that it was an old project and the i18n was outdated. It was solved, with a simple:

    bundle update
    
    0 讨论(0)
提交回复
热议问题