mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
FIX: preserve fragment identifier when escaping url
This commit is contained in:
parent
da5e7dc876
commit
1fe553873c
|
@ -12,7 +12,7 @@ class FinalDestination
|
|||
def initialize(url, opts = nil)
|
||||
@uri =
|
||||
begin
|
||||
URI(URI.escape(url)) if url
|
||||
URI(URI.escape(CGI.unescapeHTML(url), Regexp.new("[^#{URI::PATTERN::UNRESERVED}#{URI::PATTERN::RESERVED}#]"))) if url
|
||||
rescue URI::InvalidURIError
|
||||
end
|
||||
|
||||
|
|
|
@ -62,12 +62,19 @@ describe FinalDestination do
|
|||
|
||||
it "escapes url" do
|
||||
url = 'https://eviltrout.com?s=180&d=mm&r=g'
|
||||
escaped_url = URI.escape(url)
|
||||
escaped_url = URI.escape(CGI.unescapeHTML(url), Regexp.new("[^#{URI::PATTERN::UNRESERVED}#{URI::PATTERN::RESERVED}#]"))
|
||||
stub_request(:head, escaped_url).to_return(doc_response)
|
||||
|
||||
expect(fd(url).resolve.to_s).to eq(escaped_url)
|
||||
end
|
||||
|
||||
it "preserves url fragment identifier" do
|
||||
url = 'https://eviltrout.com/2016/02/25/fixing-android-performance.html#discourse-comments'
|
||||
stub_request(:head, 'https://eviltrout.com/2016/02/25/fixing-android-performance.html').to_return(doc_response)
|
||||
|
||||
expect(fd(url).resolve.to_s).to eq(url)
|
||||
end
|
||||
|
||||
it "returns the final url" do
|
||||
final = FinalDestination.new('https://eviltrout.com', opts)
|
||||
expect(final.resolve.to_s).to eq('https://eviltrout.com')
|
||||
|
|
Loading…
Reference in New Issue
Block a user