fixed #565 - undefined response when unicode URL
Showing
3 changed files
with
28 additions
and
9 deletions
... | @@ -938,15 +938,9 @@ Casper.prototype.getPageContent = function getPageContent() { | ... | @@ -938,15 +938,9 @@ Casper.prototype.getPageContent = function getPageContent() { |
938 | Casper.prototype.getCurrentUrl = function getCurrentUrl() { | 938 | Casper.prototype.getCurrentUrl = function getCurrentUrl() { |
939 | "use strict"; | 939 | "use strict"; |
940 | this.checkStarted(); | 940 | this.checkStarted(); |
941 | var url = this.evaluate(function _evaluate() { | 941 | return utils.decodeUrl(this.evaluate(function _evaluate() { |
942 | return document.location.href; | 942 | return document.location.href; |
943 | }); | 943 | })); |
944 | try { | ||
945 | return decodeURIComponent(url); | ||
946 | } catch (e) { | ||
947 | /*global unescape*/ | ||
948 | return unescape(url); | ||
949 | } | ||
950 | }; | 944 | }; |
951 | 945 | ||
952 | /** | 946 | /** |
... | @@ -1151,7 +1145,7 @@ Casper.prototype.handleReceivedResource = function(resource) { | ... | @@ -1151,7 +1145,7 @@ Casper.prototype.handleReceivedResource = function(resource) { |
1151 | return; | 1145 | return; |
1152 | } | 1146 | } |
1153 | this.resources.push(resource); | 1147 | this.resources.push(resource); |
1154 | if (resource.url !== this.requestUrl) { | 1148 | if (utils.decodeUrl(resource.url) !== this.requestUrl) { |
1155 | return; | 1149 | return; |
1156 | } | 1150 | } |
1157 | this.currentHTTPStatus = null; | 1151 | this.currentHTTPStatus = null; | ... | ... |
... | @@ -124,6 +124,22 @@ function computeModifier(modifierString, modifiers) { | ... | @@ -124,6 +124,22 @@ function computeModifier(modifierString, modifiers) { |
124 | exports.computeModifier = computeModifier; | 124 | exports.computeModifier = computeModifier; |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * Decodes a URL. | ||
128 | * @param String url | ||
129 | * @return String | ||
130 | */ | ||
131 | function decodeUrl(url) { | ||
132 | "use strict"; | ||
133 | try { | ||
134 | return decodeURIComponent(url); | ||
135 | } catch (e) { | ||
136 | /*global unescape*/ | ||
137 | return unescape(url); | ||
138 | } | ||
139 | } | ||
140 | exports.decodeUrl = decodeUrl; | ||
141 | |||
142 | /** | ||
127 | * Dumps a JSON representation of passed value to the console. Used for | 143 | * Dumps a JSON representation of passed value to the console. Used for |
128 | * debugging purpose only. | 144 | * debugging purpose only. |
129 | * | 145 | * | ... | ... |
... | @@ -75,6 +75,15 @@ if (utils.gteVersion(phantom.version, '1.9.0')) { | ... | @@ -75,6 +75,15 @@ if (utils.gteVersion(phantom.version, '1.9.0')) { |
75 | }); | 75 | }); |
76 | } | 76 | } |
77 | 77 | ||
78 | casper.test.begin('decodeUrl() tests', 4, function(test) { | ||
79 | /* global escape */ | ||
80 | test.assertEquals(utils.decodeUrl('foo'), 'foo'); | ||
81 | test.assertEquals(utils.decodeUrl('Forlì'), 'Forlì'); | ||
82 | test.assertEquals(utils.decodeUrl(encodeURIComponent('Forlì')), 'Forlì'); | ||
83 | test.assertEquals(utils.decodeUrl(escape('Forlì')), 'Forlì'); | ||
84 | test.done(); | ||
85 | }); | ||
86 | |||
78 | casper.test.begin('equals() tests', 23, function(test) { | 87 | casper.test.begin('equals() tests', 23, function(test) { |
79 | test.assert(utils.equals(null, null), 'equals() null equality'); | 88 | test.assert(utils.equals(null, null), 'equals() null equality'); |
80 | test.assertNot(utils.equals(null, undefined), 'equals() null vs. undefined inequality'); | 89 | test.assertNot(utils.equals(null, undefined), 'equals() null vs. undefined inequality'); | ... | ... |
-
Please register or sign in to post a comment