]> cat aescling's git repositories - mastodon.git/commitdiff
Fix URLs incorrectly having trailing hyphen removed (#6465)
authorDaniel King <northerner@users.noreply.github.com>
Sun, 11 Feb 2018 22:49:18 +0000 (22:49 +0000)
committerEugen Rochko <eugen@zeonfederated.com>
Sun, 11 Feb 2018 22:49:18 +0000 (23:49 +0100)
In cases where a URL has a trailing hyphen the FetchLinkCardService incorrectly removes the hyphen when it is parsed

The hyphen is not a reserved character in the URI spec https://tools.ietf.org/html/rfc3986#section-2.2

config/initializers/twitter_regex.rb
spec/services/fetch_link_card_service_spec.rb

index e924fac2280e05f0b13dcc1861d66f01e34ebc30..7fa828300bb5a08868cbf4fbbce49a9684db8854 100644 (file)
@@ -2,7 +2,7 @@ module Twitter
   class Regex
 
     REGEXEN[:valid_general_url_path_chars] = /[^\p{White_Space}\(\)\?]/iou
-    REGEXEN[:valid_url_path_ending_chars] = /[^\p{White_Space}\(\)\?!\*';:=\,\.\$%\[\]\p{Pd}~&\|@]|(?:#{REGEXEN[:valid_url_balanced_parens]})/iou
+    REGEXEN[:valid_url_path_ending_chars] = /[^\p{White_Space}\(\)\?!\*';:=\,\.\$%\[\]~&\|@]|(?:#{REGEXEN[:valid_url_balanced_parens]})/iou
     REGEXEN[:valid_url_balanced_parens] = /
       \(
         (?:
index ba61d22c3404d1a1ca7d378bee70956bed14f2b6..edacc4425c7c369710758199a548148db9e8b1b1 100644 (file)
@@ -15,6 +15,8 @@ RSpec.describe FetchLinkCardService do
     stub_request(:head, 'http://example.com/日本語').to_return(status: 200, headers: { 'Content-Type' => 'text/html' })
     stub_request(:get, 'http://example.com/日本語').to_return(request_fixture('sjis.txt'))
     stub_request(:head, 'https://github.com/qbi/WannaCry').to_return(status: 404)
+    stub_request(:head, 'http://example.com/test-').to_return(status: 200, headers: { 'Content-Type' => 'text/html' })
+    stub_request(:get, 'http://example.com/test-').to_return(request_fixture('idn.txt'))
 
     subject.call(status)
   end
@@ -63,6 +65,14 @@ RSpec.describe FetchLinkCardService do
         expect(status.preview_cards.first.title).to eq("SJISのページ")
       end
     end
+
+    context do
+      let(:status) { Fabricate(:status, text: 'test http://example.com/test-') }
+
+      it 'works with a URL ending with a hyphen' do
+        expect(a_request(:get, 'http://example.com/test-')).to have_been_made.at_least_once
+      end
+    end
   end
 
   context 'in a remote status' do