Commit 54ea8957 54ea89578fcd7d0175a7c07ba2029d0c70f79dbd by Nicolas Perriault

fixed opening truncated/uncomplete root urls may give erroneous HTTP statuses

1 parent a2ab8b42
......@@ -68,6 +68,7 @@ The documentation has been [updated accordingly](http://casperjs.org/api.html#ca
- a new `onWaitTimeout` option has been added, to allow defining a default behavior when a `waitFor*` function times out.
- [Casper.resourceExists()](http://casperjs.org/api.html#casper.resourceExists) and related functions now checks for non HTTP-404 received responses.
- fixed [#167](https://github.com/n1k0/casperjs/issues/167) - fixed opening truncated/uncomplete root urls may give erroneous HTTP statuses
- closes [#205](https://github.com/n1k0/casperjs/issues/205) - [`debugHTML()`](http://casperjs.org/api.html#casper.debugHTML) can have a selector passed; added [`getHTML()`](http://casperjs.org/api.html#casper.getHTML)
- closes [#230](https://github.com/n1k0/casperjs/issues/230) - added [`ClientUtils.getElementsBound()`](http://casperjs.org/api.html#clientutils.getElementsBounds) and [`Casper.getElementsBound()`](http://casperjs.org/api.html#casper.getElementsBounds)
- fixed [#235](https://github.com/n1k0/casperjs/issues/235) - updated `Casper.evaluate()` to use phantomjs >= 1.6 native one. As a consequence, **the `injector` module is marked as deprecated**.
......
......@@ -1016,6 +1016,8 @@ Casper.prototype.open = function open(location, settings) {
throw new CasperError("open(): invalid request settings data value: " + settings.data);
}
}
// clean location
location = utils.cleanUrl(location);
// current request url
this.requestUrl = this.filter('open.location', location) || location;
// http auth
......
......@@ -51,6 +51,21 @@
exports.betterTypeOf = betterTypeOf;
/**
* Cleans a passed URL if it lacks a slash at the end when a sole domain is used.
*
* @param String url An HTTP URL
* @return String
*/
function cleanUrl(url) {
var match = /(https?):\/\/(.*)/i.exec(url);
if (!match || match.length !== 3) {
return url;
}
return format("%s://%s/", match[1], match[2]); // notice the trailing slash
}
exports.cleanUrl = cleanUrl;
/**
* Dumps a JSON representation of passed value to the console. Used for
* debugging purpose only.
*
......
......@@ -2,9 +2,22 @@ var utils = require('utils'),
t = casper.test,
x = require('casper').selectXPath;
t.comment('cleanUrl()');
(function() {
var testCases = {
'http://google.com/': 'http://google.com/',
'http://google.com': 'http://google.com/',
'http://www.google.com/': 'http://www.google.com/',
'http://www.google.com/?plop=2': 'http://www.google.com/?plop=2',
'https://google.com/': 'https://google.com/',
'https://google.com': 'https://google.com/',
'https://www.google.com/': 'https://www.google.com/',
'https://www.google.com/?plop=2': 'https://www.google.com/?plop=2'
};
})();
t.comment('equals()');
(function() {
t.comment('Tester.testEquals()');
t.assert(utils.equals(null, null), 'Tester.testEquals() null equality');
t.assertNot(utils.equals(null, undefined), 'Tester.testEquals() null vs. undefined inequality');
t.assert(utils.equals("hi", "hi"), 'Tester.testEquals() string equality');
......