Merge pull request #5879 from SuperTux88/encode-urls
encode unencoded urls and normalize IDN urls
This commit is contained in:
commit
b06a699dd6
2 changed files with 18 additions and 1 deletions
|
|
@ -239,7 +239,9 @@ module Diaspora
|
||||||
# Extracts all the urls from the raw message and return them in the form of a string
|
# Extracts all the urls from the raw message and return them in the form of a string
|
||||||
# Different URLs are seperated with a space
|
# Different URLs are seperated with a space
|
||||||
def urls
|
def urls
|
||||||
@urls ||= Twitter::Extractor.extract_urls(plain_text_without_markdown)
|
@urls ||= Twitter::Extractor.extract_urls(plain_text_without_markdown).map {|url|
|
||||||
|
Addressable::URI.parse(url).normalize.to_s
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def raw
|
def raw
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,21 @@ describe Diaspora::MessageRenderer do
|
||||||
text = "[](https://www.antifainfoblatt.de/artikel/%E2%80%9Eschlie%C3%9Flich-waren-es-zu-viele%E2%80%9C)"
|
text = "[](https://www.antifainfoblatt.de/artikel/%E2%80%9Eschlie%C3%9Flich-waren-es-zu-viele%E2%80%9C)"
|
||||||
expect(message(text).urls).to eq ["https://www.antifainfoblatt.de/sites/default/files/public/styles/front_full/public/jockpalfreeman.png?itok=OPjHKpmt", "https://www.antifainfoblatt.de/artikel/%E2%80%9Eschlie%C3%9Flich-waren-es-zu-viele%E2%80%9C"]
|
expect(message(text).urls).to eq ["https://www.antifainfoblatt.de/sites/default/files/public/styles/front_full/public/jockpalfreeman.png?itok=OPjHKpmt", "https://www.antifainfoblatt.de/artikel/%E2%80%9Eschlie%C3%9Flich-waren-es-zu-viele%E2%80%9C"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "encodes extracted urls" do
|
||||||
|
url = "http://www.example.com/url/with/umlauts/ä/index.html"
|
||||||
|
expect(message(url).urls).to eq ["http://www.example.com/url/with/umlauts/%C3%A4/index.html"]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "not double encodes an already encoded url" do
|
||||||
|
encoded_url = "http://www.example.com/url/with/umlauts/%C3%A4/index.html"
|
||||||
|
expect(message(encoded_url).urls).to eq [encoded_url]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "parses IDN correctly" do
|
||||||
|
url = "http://www.hören.at/"
|
||||||
|
expect(message(url).urls).to eq ["http://www.xn--hren-5qa.at/"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#plain_text_for_json" do
|
describe "#plain_text_for_json" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue