Browse Source

Fix URLs incorrectly having trailing hyphen removed (#6465)

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
master
Daniel King 6 years ago
committed by Eugen Rochko
parent
commit
6ef3874b2e
2 changed files with 11 additions and 1 deletions
  1. +1
    -1
      config/initializers/twitter_regex.rb
  2. +10
    -0
      spec/services/fetch_link_card_service_spec.rb

+ 1
- 1
config/initializers/twitter_regex.rb View File

@ -2,7 +2,7 @@ module Twitter
class Regex class Regex
REGEXEN[:valid_general_url_path_chars] = /[^\p{White_Space}\(\)\?]/iou 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] = / REGEXEN[:valid_url_balanced_parens] = /
\( \(
(?: (?:

+ 10
- 0
spec/services/fetch_link_card_service_spec.rb View 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(: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(: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, '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) subject.call(status)
end end
@ -63,6 +65,14 @@ RSpec.describe FetchLinkCardService do
expect(status.preview_cards.first.title).to eq("SJISのページ") expect(status.preview_cards.first.title).to eq("SJISのページ")
end end
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 end
context 'in a remote status' do context 'in a remote status' do

Loading…
Cancel
Save