fixed opening truncated/uncomplete root urls may give erroneous HTTP statuses
Showing
4 changed files
with
32 additions
and
1 deletions
... | @@ -68,6 +68,7 @@ The documentation has been [updated accordingly](http://casperjs.org/api.html#ca | ... | @@ -68,6 +68,7 @@ The documentation has been [updated accordingly](http://casperjs.org/api.html#ca |
68 | 68 | ||
69 | - a new `onWaitTimeout` option has been added, to allow defining a default behavior when a `waitFor*` function times out. | 69 | - a new `onWaitTimeout` option has been added, to allow defining a default behavior when a `waitFor*` function times out. |
70 | - [Casper.resourceExists()](http://casperjs.org/api.html#casper.resourceExists) and related functions now checks for non HTTP-404 received responses. | 70 | - [Casper.resourceExists()](http://casperjs.org/api.html#casper.resourceExists) and related functions now checks for non HTTP-404 received responses. |
71 | - fixed [#167](https://github.com/n1k0/casperjs/issues/167) - fixed opening truncated/uncomplete root urls may give erroneous HTTP statuses | ||
71 | - 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) | 72 | - 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) |
72 | - 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) | 73 | - 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) |
73 | - 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**. | 74 | - 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) { | ... | @@ -1016,6 +1016,8 @@ Casper.prototype.open = function open(location, settings) { |
1016 | throw new CasperError("open(): invalid request settings data value: " + settings.data); | 1016 | throw new CasperError("open(): invalid request settings data value: " + settings.data); |
1017 | } | 1017 | } |
1018 | } | 1018 | } |
1019 | // clean location | ||
1020 | location = utils.cleanUrl(location); | ||
1019 | // current request url | 1021 | // current request url |
1020 | this.requestUrl = this.filter('open.location', location) || location; | 1022 | this.requestUrl = this.filter('open.location', location) || location; |
1021 | // http auth | 1023 | // http auth | ... | ... |
... | @@ -51,6 +51,21 @@ | ... | @@ -51,6 +51,21 @@ |
51 | exports.betterTypeOf = betterTypeOf; | 51 | exports.betterTypeOf = betterTypeOf; |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Cleans a passed URL if it lacks a slash at the end when a sole domain is used. | ||
55 | * | ||
56 | * @param String url An HTTP URL | ||
57 | * @return String | ||
58 | */ | ||
59 | function cleanUrl(url) { | ||
60 | var match = /(https?):\/\/(.*)/i.exec(url); | ||
61 | if (!match || match.length !== 3) { | ||
62 | return url; | ||
63 | } | ||
64 | return format("%s://%s/", match[1], match[2]); // notice the trailing slash | ||
65 | } | ||
66 | exports.cleanUrl = cleanUrl; | ||
67 | |||
68 | /** | ||
54 | * Dumps a JSON representation of passed value to the console. Used for | 69 | * Dumps a JSON representation of passed value to the console. Used for |
55 | * debugging purpose only. | 70 | * debugging purpose only. |
56 | * | 71 | * | ... | ... |
... | @@ -2,9 +2,22 @@ var utils = require('utils'), | ... | @@ -2,9 +2,22 @@ var utils = require('utils'), |
2 | t = casper.test, | 2 | t = casper.test, |
3 | x = require('casper').selectXPath; | 3 | x = require('casper').selectXPath; |
4 | 4 | ||
5 | t.comment('cleanUrl()'); | ||
6 | (function() { | ||
7 | var testCases = { | ||
8 | 'http://google.com/': 'http://google.com/', | ||
9 | 'http://google.com': 'http://google.com/', | ||
10 | 'http://www.google.com/': 'http://www.google.com/', | ||
11 | 'http://www.google.com/?plop=2': 'http://www.google.com/?plop=2', | ||
12 | 'https://google.com/': 'https://google.com/', | ||
13 | 'https://google.com': 'https://google.com/', | ||
14 | 'https://www.google.com/': 'https://www.google.com/', | ||
15 | 'https://www.google.com/?plop=2': 'https://www.google.com/?plop=2' | ||
16 | }; | ||
17 | })(); | ||
18 | |||
5 | t.comment('equals()'); | 19 | t.comment('equals()'); |
6 | (function() { | 20 | (function() { |
7 | t.comment('Tester.testEquals()'); | ||
8 | t.assert(utils.equals(null, null), 'Tester.testEquals() null equality'); | 21 | t.assert(utils.equals(null, null), 'Tester.testEquals() null equality'); |
9 | t.assertNot(utils.equals(null, undefined), 'Tester.testEquals() null vs. undefined inequality'); | 22 | t.assertNot(utils.equals(null, undefined), 'Tester.testEquals() null vs. undefined inequality'); |
10 | t.assert(utils.equals("hi", "hi"), 'Tester.testEquals() string equality'); | 23 | t.assert(utils.equals("hi", "hi"), 'Tester.testEquals() string equality'); | ... | ... |
-
Please register or sign in to post a comment