Skip to content
Extraits de code Groupes Projets
Valider 39810e61 rédigé par Florian Staudacher's avatar Florian Staudacher
Parcourir les fichiers

decode URLs before processing them (fixes #4507)

parent 134c7faf
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -43,6 +43,12 @@ $(function() { ...@@ -43,6 +43,12 @@ $(function() {
unicodeUrl += ')'; unicodeUrl += ')';
urlSuffix = '>'; urlSuffix = '>';
} }
// url*DE*code as much as possible
while( unicodeUrl.indexOf("%") !== -1 && unicodeUrl != decodeURI(unicodeUrl) ) {
unicodeUrl = decodeURI(unicodeUrl);
}
// markdown doesn't like '(' or ')' anywhere, except where it wants // markdown doesn't like '(' or ')' anywhere, except where it wants
var workingUrl = unicodeUrl.replace(/\(/, "%28").replace(/\)/, "%29"); var workingUrl = unicodeUrl.replace(/\(/, "%28").replace(/\)/, "%29");
......
...@@ -158,6 +158,24 @@ describe("app.helpers.textFormatter", function(){ ...@@ -158,6 +158,24 @@ describe("app.helpers.textFormatter", function(){
expect(parsed).toContain(text); expect(parsed).toContain(text);
}); });
context("percent-encoded input url", function() {
beforeEach(function() {
this.input = "http://www.soilandhealth.org/01aglibrary/010175.tree%20crops.pdf" // #4507
this.correctHref = 'href="'+this.input+'"';
});
it("doesn't get double-encoded", function(){
var parsed = this.formatter.markdownify(this.input);
expect(parsed).toContain(this.correctHref);
});
it("gets correctly decoded, even when multiply encoded", function() {
var uglyUrl = encodeURI(encodeURI(encodeURI(this.input)));
var parsed = this.formatter.markdownify(uglyUrl);
expect(parsed).toContain(this.correctHref);
});
});
it("tests a bunch of benchmark urls", function(){ it("tests a bunch of benchmark urls", function(){
var self = this; var self = this;
$.ajax({ $.ajax({
......
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