decode URLs before processing them (fixes #4507)

This commit is contained in:
Florian Staudacher 2013-09-21 15:23:30 +02:00
parent 134c7faf45
commit 39810e6196
2 changed files with 24 additions and 0 deletions

View file

@ -43,6 +43,12 @@ $(function() {
unicodeUrl += ')';
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
var workingUrl = unicodeUrl.replace(/\(/, "%28").replace(/\)/, "%29");

View file

@ -158,6 +158,24 @@ describe("app.helpers.textFormatter", function(){
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(){
var self = this;
$.ajax({