Project

General

Profile

Actions

バグ #1217

closed

非ASCII文字が含まれるURIをDiva::URI.newすると例外が発生する

Added by cob odo over 6 years ago. Updated over 6 years ago.

Status:
終了
Priority:
通常
Assignee:
Target version:
プラグイン名:
クラッシュする:
Yes

Description

コンソールで試すと、直接Addressableを使うケースでは

>>> uri = 'https://こっち.みんな/ておくれ'
Addressable::URI.parse(uri)

#<Addressable::URI:0x3facea12b070 URI:https://こっち.みんな/ておくれ>

のように正しく生成できますが、Diva::URIでは
>>> uri = 'https://こっち.みんな/ておくれ'
Diva::URI.new(uri).host

URI::InvalidURIError: URI must be ascii only "https://\u3053\u3063\u3061.\u307F\u3093\u306A/\u3066\u304A\u304F\u308C" 
/home/cobodo/repos/mikutter/core/plugin/console/console.rb:33:in `instance_eval'
/home/cobodo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/uri/rfc3986_parser.rb:73:in `parse'
/home/cobodo/.rbenv/versions/2.5.1/lib/ruby/2.5.0/uri/common.rb:237:in `parse'
/home/cobodo/repos/mikutter/vendor/bundle/ruby/2.5.0/gems/diva-0.3.1/lib/diva/uri.rb:121:in `generate_uri_by_string'
/home/cobodo/repos/mikutter/vendor/bundle/ruby/2.5.0/gems/diva-0.3.1/lib/diva/uri.rb:113:in `generate_uri'
/home/cobodo/repos/mikutter/vendor/bundle/ruby/2.5.0/gems/diva-0.3.1/lib/diva/uri.rb:75:in `to_uri'
/home/cobodo/repos/mikutter/vendor/bundle/ruby/2.5.0/gems/diva-0.3.1/lib/diva/uri.rb:104:in `method_missing'
(eval):3:in `block (3 levels) in <top (required)>'
/home/cobodo/repos/mikutter/core/plugin/console/console.rb:33:in `instance_eval'
/home/cobodo/repos/mikutter/core/plugin/console/console.rb:33:in `block (3 levels) in <top (required)>'
/home/cobodo/repos/mikutter/core/mui/gtk_extension.rb:35:in `block in safety_signal_connect'
/home/cobodo/repos/mikutter/core/plugin/gtk/mainloop.rb:10:in `main'
/home/cobodo/repos/mikutter/core/plugin/gtk/mainloop.rb:10:in `mainloop'
./mikutter.rb:68:in `boot!'
./mikutter.rb:104:in `<main>'

のように例外が発生します。
メッセージ上のハイパーリンク先としてこういったURIが指定されていると、mikutterごとクラッシュします。

diva gemのlib/diva/uri.rbのgenerate_uri_by_stringメソッドではURI::InvalidComponentErrorのみをrescueしていますが、ここで発生しているのはURI::InvalidURIErrorです。

下記のように共通のスーパークラスであるURI::Errorでrescueするようにすると、例外を発生させず、正しく処理できるようです。

>>> class Diva::URI
  def generate_uri_by_string
    URI.parse(@uri_string)
  rescue URI::Error
    Addressable::URI.parse(@uri_string)
  end
end

uri = 'https://こっち.みんな/ておくれ'
Diva::URI.new(uri).host

"こっち.みんな" 

再現手順

・mastodonで非ASCII文字を含むURIをtootする(例: https://mstdn.kanagu.info/@cobodo/99929919005373666
・worldonプラグインを使ってmikutter上で表示し、ハイパーリンクをクリックする。

Actions #1

Updated by cob odo over 6 years ago

Diva::URIの元になった(らしい)Retriever::URIはgenerate_uri_by_stringの実装が微妙に違うので、特に問題にはならないようでした。

Actions #2

Updated by toshi_a 初音 over 6 years ago

  • Status changed from 分類待ち to 実装待ち
  • Assignee set to toshi_a 初音

これはAdressable::URIを使ってほしいので、この修正を取り込もうと思います。

Actions #3

Updated by toshi_a 初音 over 6 years ago

  • Status changed from 実装待ち to レビュー待ち
  • Assignee changed from toshi_a 初音 to cob odo
  • ブランチ set to topic/1217-diva-0.3.2
>>> uri = 'https://こっち.みんな/ておくれ'
Diva::URI.new(uri).host
"こっち.みんな" 

修正を適用した diva 0.3.2をリリースしました。mikutter側でも、このブランチでdiva 0.3.2を要求するようにしたので、確認してみてください。

Actions #4

Updated by toshi_a 初音 over 6 years ago

これで特に問題なければ、masterにmergeして、このチケットは終了にしておいてください。

Actions #5

Updated by cob odo over 6 years ago

  • Status changed from レビュー待ち to 終了

ありがとうございます、確認しました。

ハイパーリンクの挙動もコンソール上の挙動も問題なさそうでしたので、mergeしてpushしました。チケットは終了にしておきます。

Actions

Also available in: Atom PDF