Commit bc1a5ba6 bc1a5ba6440c60081b2cf444030107c6801c0153 by Nicolas Perriault

Merge pull request #1033 from diox/resource-exists-no-regexp

refs #1032 - Don't use a regexp search for string search in resourceExists

Please note that this breaks backward compatibility when passing a string to resourceExists(); previously the .search() String method was used, preventing passing url strings containing a question mark easily. We're now strictly checking for an exact match. For searching for a more flexible pattern, you can keep passing in a RegExp.
2 parents ae424f2e 584ab551
......@@ -1488,7 +1488,7 @@ Casper.prototype.resourceExists = function resourceExists(test) {
switch (utils.betterTypeOf(test)) {
case "string":
testFn = function _testResourceExists_String(res) {
return res.url.search(test) !== -1 && res.status !== 404;
return res.url.indexOf(test) !== -1 && res.status !== 404;
};
break;
case "regexp":
......
......@@ -8,7 +8,7 @@
<script id="loader"></script>
<script>
setTimeout(function () {
document.querySelector("#loader").setAttribute("src", "dummy.js");
document.querySelector("#loader").setAttribute("src", "dummy.js?querystring");
}, 1000);
</script>
</body>
......
......@@ -11,7 +11,7 @@ casper.test.begin("Basic resources tests", 5, function(test) {
test.assertResourceExists(function(res) {
return res.url.match("dummy.js");
}, "phantom image found via test Function");
test.assertResourceExists("dummy.js", "phantom image found via test String");
test.assertResourceExists("dummy.js?querystring", "phantom image found via test String");
}, function onTimeout() {
test.fail("waitForResource timeout occured");
});
......