diff --git a/lib/notification.js b/lib/notification.js index 09ef735..db18f84 100644 --- a/lib/notification.js +++ b/lib/notification.js @@ -321,7 +321,8 @@ Notification.prototype.trim = function(length) { return length - tooLong; } escaped = this.truncateStringToLength(escaped, length - tooLong, encoding); - escaped = escaped.replace(/(\\+|\\u[0-9a-fA-F]{0,3})$/, ""); + escaped = escaped.replace(/(\\u[0-9a-fA-F]{0,3})$/, ""); + escaped = escaped.replace(/([^\\])\\$/, "$1"); var trimmed = Buffer.byteLength(escaped, encoding); escaped = JSON.parse("\"" + escaped + "\""); diff --git a/test/notification.js b/test/notification.js index 3c8462f..461a4b2 100644 --- a/test/notification.js +++ b/test/notification.js @@ -142,10 +142,16 @@ describe("Notification", function() { note.trim(trimLength); expect(note.alert).to.equal("\n\n"); }); + + it("leaves escaped escape character intact", function() { + note.alert = "test\\ message"; + note.trim(26); + expect(note.alert).to.equal("test\\"); + }); it("strips orphaned escape character", function () { note.alert = "test\\ message"; - note.trim(26); + note.trim(25); expect(note.alert).to.equal("test"); }); });