Skip to content

Commit

Permalink
Merge pull request TryGhost#1729 from mjbshaw/escape-regex
Browse files Browse the repository at this point in the history
Escape URL for use in regex
  • Loading branch information
ErisDS committed Dec 21, 2013
2 parents e9e9937 + a785696 commit f0b0291
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/test/functional/admin/editor_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*globals casper, __utils__, url, testPost */

var escapedUrl = url.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");

CasperTest.begin("Ghost editor is correct", 10, function suite(test) {
casper.thenOpen(url + "ghost/editor/", function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
Expand Down Expand Up @@ -32,7 +34,7 @@ CasperTest.begin("Ghost editor is correct", 10, function suite(test) {
casper.thenClick('.js-publish-button');

casper.waitForResource(/posts/, function checkPostWasCreated() {
var urlRegExp = new RegExp("^" + url + "ghost\/editor\/[0-9]*");
var urlRegExp = new RegExp("^" + escapedUrl + "ghost\/editor\/[0-9]*");
test.assertUrlMatch(urlRegExp, 'got an id on our URL');
test.assertExists('.notification-success', 'got success notification');
test.assertEvalEquals(function () {
Expand Down Expand Up @@ -163,7 +165,7 @@ CasperTest.begin('Publish menu - existing post', 22, function suite(test) {
casper.thenClick('.js-publish-button');

casper.waitForResource(/posts/, function checkPostWasCreated() {
var urlRegExp = new RegExp("^" + url + "ghost\/editor\/[0-9]*");
var urlRegExp = new RegExp("^" + escapedUrl + "ghost\/editor\/[0-9]*");
test.assertUrlMatch(urlRegExp, 'got an id on our URL');
});

Expand Down Expand Up @@ -200,7 +202,7 @@ CasperTest.begin('Publish menu - existing post', 22, function suite(test) {
casper.thenClick('.js-publish-button');

casper.waitForResource(/posts/, function checkPostWasCreated() {
var urlRegExp = new RegExp("^" + url + "ghost\/editor\/[0-9]*");
var urlRegExp = new RegExp("^" + escapedUrl + "ghost\/editor\/[0-9]*");
test.assertUrlMatch(urlRegExp, 'got an id on our URL');
});

Expand Down Expand Up @@ -236,4 +238,4 @@ CasperTest.begin('Publish menu - existing post', 22, function suite(test) {
}, function onTimeout() {
test.assert(false, 'Publish split button should have .splitbutton-delete');
});
});
});

0 comments on commit f0b0291

Please sign in to comment.