From 57c6abb19cc9c67fd89d364f47dbc5f2bd0732b1 Mon Sep 17 00:00:00 2001 From: Magnar Sveen Date: Fri, 24 Jun 2011 07:41:51 +0200 Subject: [PATCH] escaped $ in growl messages --- icons/{ok.png => clean.png} | Bin icons/{no.png => error.png} | Bin lib/growl-reporter.js | 27 ++++++++++++++------------- test/growl-reporter-test.js | 6 ++++++ todo.md | 2 -- 5 files changed, 20 insertions(+), 15 deletions(-) rename icons/{ok.png => clean.png} (100%) rename icons/{no.png => error.png} (100%) diff --git a/icons/ok.png b/icons/clean.png similarity index 100% rename from icons/ok.png rename to icons/clean.png diff --git a/icons/no.png b/icons/error.png similarity index 100% rename from icons/no.png rename to icons/error.png diff --git a/lib/growl-reporter.js b/lib/growl-reporter.js index ec48d25..82bbdba 100644 --- a/lib/growl-reporter.js +++ b/lib/growl-reporter.js @@ -13,15 +13,23 @@ function listen() { this.repository.on('errorsFixed', this.handleErrorsFixed.bind(this)); } +function escape(text) { + return text.replace('$', '\\$'); +} + +function notify(title, text, icon) { + growl.notify(escape(text), { + title: escape(title), + image: __dirname + '/../icons/' + icon + '.png' + }); +} + function handleErrorsIntroduced(file, errors) { var error = 'First error at line ' + errors[0].line + ' char ' + errors[0].character + ':\n' + errors[0].reason; var title = 'You introduced ' + pluralize(errors.length, 'lint error') + ' in ' + file.name + ':'; - growl.notify(error, { - title: title, - image: __dirname + '/../icons/no.png' - }); + notify(title, error, 'error'); } var cheers = [ @@ -52,10 +60,7 @@ function cheer() { } function congratulate(file) { - growl.notify(file.name + ' is clean.', { - title: cheer(), - image: __dirname + '/../icons/ok.png' - }); + notify(cheer(), file.name + ' is clean.', 'clean'); } function nextError(file) { @@ -63,11 +68,7 @@ function nextError(file) { var text = 'Next error at line ' + error.line + ' char ' + error.character + ':\n' + error.reason; - var title = 'Nice cleanup!'; - growl.notify(text, { - title: title, - image: __dirname + '/../icons/more.png' - }); + notify('Nice cleanup!', text, 'more'); } function handleErrorsFixed(file, fixedError) { diff --git a/test/growl-reporter-test.js b/test/growl-reporter-test.js index 8debc5b..536cc59 100644 --- a/test/growl-reporter-test.js +++ b/test/growl-reporter-test.js @@ -67,5 +67,11 @@ buster.testCase("growlReporter", { reason: 'Bah, humbug!' }]}, [{}]); assert.calledWith(growl.notify, 'Next error at line 19 char 0:\nBah, humbug!'); + }, + + "should escape $": function () { + this.reporter.handleErrorsFixed({name: 'file$.js', errors: []}, [{}]); + assert.calledWith(growl.notify, 'file\\$.js is clean.'); } + }); diff --git a/todo.md b/todo.md index 0c8fadf..935436a 100644 --- a/todo.md +++ b/todo.md @@ -1,7 +1,5 @@ Todo ==== -* `$` needs to be escaped in growl messages - * being blamed for introducing an error, AND praised for fixing it, when changing around whitespace (changes lines)