Commit f6b352ee f6b352ee0ec3d77d16323ae8c3b704161163fe4f by Nicolas Perriault

fixed #565 - undefined response when unicode URL

1 parent e6e192ff
......@@ -938,15 +938,9 @@ Casper.prototype.getPageContent = function getPageContent() {
Casper.prototype.getCurrentUrl = function getCurrentUrl() {
"use strict";
this.checkStarted();
var url = this.evaluate(function _evaluate() {
return utils.decodeUrl(this.evaluate(function _evaluate() {
return document.location.href;
});
try {
return decodeURIComponent(url);
} catch (e) {
/*global unescape*/
return unescape(url);
}
}));
};
/**
......@@ -1151,7 +1145,7 @@ Casper.prototype.handleReceivedResource = function(resource) {
return;
}
this.resources.push(resource);
if (resource.url !== this.requestUrl) {
if (utils.decodeUrl(resource.url) !== this.requestUrl) {
return;
}
this.currentHTTPStatus = null;
......
......@@ -124,6 +124,22 @@ function computeModifier(modifierString, modifiers) {
exports.computeModifier = computeModifier;
/**
* Decodes a URL.
* @param String url
* @return String
*/
function decodeUrl(url) {
"use strict";
try {
return decodeURIComponent(url);
} catch (e) {
/*global unescape*/
return unescape(url);
}
}
exports.decodeUrl = decodeUrl;
/**
* Dumps a JSON representation of passed value to the console. Used for
* debugging purpose only.
*
......
......@@ -75,6 +75,15 @@ if (utils.gteVersion(phantom.version, '1.9.0')) {
});
}
casper.test.begin('decodeUrl() tests', 4, function(test) {
/* global escape */
test.assertEquals(utils.decodeUrl('foo'), 'foo');
test.assertEquals(utils.decodeUrl('Forlì'), 'Forlì');
test.assertEquals(utils.decodeUrl(encodeURIComponent('Forlì')), 'Forlì');
test.assertEquals(utils.decodeUrl(escape('Forlì')), 'Forlì');
test.done();
});
casper.test.begin('equals() tests', 23, function(test) {
test.assert(utils.equals(null, null), 'equals() null equality');
test.assertNot(utils.equals(null, undefined), 'equals() null vs. undefined inequality');
......