Skip to content
Extraits de code Groupes Projets
Valider a863f3eb rédigé par Benjamin Neff's avatar Benjamin Neff
Parcourir les fichiers

encode unencoded urls and normalize IDN urls

parent 0bad6dba
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -239,7 +239,9 @@ module Diaspora ...@@ -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 ...@@ -199,6 +199,21 @@ describe Diaspora::MessageRenderer do
text = "[![Image](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)" text = "[![Image](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"] 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
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter