Comparing version 1.7.2 to 1.7.3
## Changelog | ||
1.7.3: | ||
* Added support for increased payload length for VoIP applications (Closes #207) | ||
* Fixed a bug with trimming UTF-16 encoded payloads | ||
* Dropped support for node v0.6 as it doesn't support UTF-16 surrogate pairs. Plus it's old. It'll still work if needed though, if you use UTF-8. | ||
1.7.2: | ||
@@ -4,0 +10,0 @@ |
@@ -12,5 +12,5 @@ "use strict"; | ||
// Setup a connection to the feedback service using a custom interval (10 seconds) | ||
var feedback = new apn.feedback({ address:"feedback.sandbox.push.apple.com", interval: 10 }); | ||
var feedback = new apn.feedback({ production: false, interval: 10 }); | ||
feedback.on("feedback", handleFeedback); | ||
feedback.on("feedbackError", console.error); |
@@ -12,3 +12,3 @@ var apn = require ("../index.js"); | ||
var service = new apn.connection({ gateway:"gateway.sandbox.push.apple.com" }); | ||
var service = new apn.connection({ production: false }); | ||
@@ -15,0 +15,0 @@ service.on("connected", function() { |
@@ -59,2 +59,3 @@ "use strict"; | ||
production: (process.env.NODE_ENV === "production"), | ||
voip: false, | ||
address: null, | ||
@@ -707,4 +708,5 @@ port: 2195, | ||
var messageLength = notification.length(); | ||
if (messageLength > 2048) { | ||
var maxLength = (this.options.voip ? 4096 : 2048); | ||
if (messageLength > maxLength) { | ||
util.setImmediate(function () { | ||
@@ -711,0 +713,0 @@ this.raiseError(Errors['invalidPayloadSize'], notification, recipient); |
@@ -108,2 +108,9 @@ "use strict"; | ||
Notification.prototype.getAlertText = function () { | ||
if(typeof this.alert === "object") { | ||
return this.alert.body; | ||
} | ||
return this.alert; | ||
}; | ||
/** | ||
@@ -289,2 +296,3 @@ * Set the alert text for the notification | ||
Notification.prototype.length = function () { | ||
this.compiled = false; | ||
return Buffer.byteLength(this.compile(), this.encoding || "utf8"); | ||
@@ -321,12 +329,8 @@ }; | ||
} | ||
escaped = this.truncateStringToLength(escaped, length - tooLong); | ||
escaped = escaped.replace(/(\\|\\x\d{0,1}|\\u\d{0,3})$/, ""); | ||
escaped = this.truncateStringToLength(escaped, length - tooLong, encoding); | ||
escaped = escaped.replace(/(\\|\\u[0-9a-fA-F]{0,3})$/, ""); | ||
escaped = JSON.parse("\"" + escaped + "\""); | ||
if (typeof this.alert === "string") { | ||
this.alert = escaped; | ||
} | ||
else { | ||
this.alert.body = escaped; | ||
} | ||
this.setAlertText(escaped); | ||
return tooLong; | ||
@@ -341,8 +345,6 @@ }; | ||
Notification.prototype.compile = function () { | ||
if(this.compiled) { | ||
return this.compiledPayload; | ||
if(!this.compiled) { | ||
this.compiled = JSON.stringify(this); | ||
} | ||
this.compiledPayload = JSON.stringify(this); | ||
this.compiled = true; | ||
return this.compiledPayload; | ||
return this.compiled; | ||
}; | ||
@@ -367,5 +369,5 @@ | ||
*/ | ||
Notification.prototype.truncateStringToLength = function (string, length) { | ||
Notification.prototype.truncateStringToLength = function (string, length, encoding) { | ||
// Convert to a buffer and back to a string with the correct encoding to truncate the unicode series correctly. | ||
var result = new Buffer(string, this.encoding || "utf8").toString(this.encoding || "utf8", 0, length); | ||
var result = new Buffer(string, encoding).toString(encoding, 0, length); | ||
@@ -386,6 +388,4 @@ if (this.truncateAtWordEnd === true) { | ||
// has been removed. | ||
var encoding = this.encoding || "utf8"; | ||
if (encoding === "utf8" || encoding === "utf16le" || encoding === "ucs2") { | ||
while( !hasValidUnicodeTail(result, encoding) ) { | ||
while( result.length > 0 && !hasValidUnicodeTail(result, encoding) ) { | ||
result = result.substr(0, result.length - 1); | ||
@@ -392,0 +392,0 @@ } |
{ | ||
"name": "apn", | ||
"description": "An interface to the Apple Push Notification service for Node.js", | ||
"version": "1.7.2", | ||
"version": "1.7.3", | ||
"author": "Andrew Naylor <argon@mkbot.net>", | ||
@@ -31,9 +31,9 @@ "contributors": [ | ||
"node-forge": "0.6.x", | ||
"q": "1.1.x" | ||
"q": ">1.1.0 < 2.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "1.x", | ||
"chai": "2.x", | ||
"chai-as-promised": "*", | ||
"mocha": "*", | ||
"rewire": "2.2.x", | ||
"rewire": "2.3.x", | ||
"sinon": "1.x", | ||
@@ -49,5 +49,5 @@ "sinon-chai": "2.x" | ||
"engines": { | ||
"node": ">= 0.6.14" | ||
"node": ">= 0.8.0" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -421,2 +421,36 @@ var rewire = require("rewire"); | ||
}); | ||
describe("validNotification", function() { | ||
describe("notification is shorter than max allowed", function() { | ||
it("returns true", function() { | ||
var connection = Connection(); | ||
var notification = { length: function() { return 128; }}; | ||
expect(connection.validNotification(notification)).to.equal(true); | ||
}); | ||
}); | ||
describe("notification is the maximum length", function() { | ||
it("returns true", function() { | ||
var connection = Connection(); | ||
var notification = { length: function() { return 2048; }}; | ||
expect(connection.validNotification(notification)).to.equal(true); | ||
}); | ||
}); | ||
describe("notification too long", function() { | ||
it("returns false", function() { | ||
var connection = Connection(); | ||
var notification = { length: function() { return 2176; }}; | ||
expect(connection.validNotification(notification)).to.equal(false); | ||
}); | ||
}); | ||
describe("VoIP flag set", function() { | ||
it("allows longer payload", function() { | ||
var connection = Connection({"voip": true}); | ||
var notification = { length: function() { return 4096; }}; | ||
expect(connection.validNotification(notification)).to.equal(true); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -51,5 +51,5 @@ var parsePkcs12 = require("../../lib/credentials/parsePkcs12"); | ||
var certificates = credentials.certificates; | ||
for(var i in certificates) { | ||
expect(certificates[i]).to.be.an.instanceof(APNCertificate); | ||
} | ||
certificates.forEach(function(certificate) { | ||
expect(certificate).to.be.an.instanceof(APNCertificate); | ||
}); | ||
}); | ||
@@ -60,5 +60,5 @@ | ||
var certificates = credentials.certificates; | ||
for(var i in certificates) { | ||
expect(certificates[i].key().fingerprint()).to.equal(fingerprints[i]); | ||
} | ||
certificates.forEach(function(certificate, index) { | ||
expect(certificate.key().fingerprint()).to.equal(fingerprints[index]); | ||
}); | ||
}); | ||
@@ -65,0 +65,0 @@ }); |
var apn = require("../"); | ||
var sinon = require("sinon"); | ||
@@ -10,40 +11,198 @@ describe("Notification", function() { | ||
it("should trim long alert strings", function () { | ||
note.alert = 'ㅂㅈ ㅐ: LONDON (AP) — E\\\veryone says there areare lots of hidden costs to owning a home. If you own a palace, the costs are royal.\n\nThat became evident when the Buckingham Palace released its accounts Thursday, which showed the monarchy cost British taxpayers 35.7 million pounds ($60.8 million) last year — 56 pence (just under $1) for everyone in the country.\n\nThat is 7.2 percent, or 2.4 million pounds, more than the year before and the increase is mainly explained by the British royal family\'s repair bills.\n\nTheir properties are hardly typical. Buckingham Palace, for example, has 240 bedrooms and 78 bathrooms. That\'s a lot of plumbing to fix when things go wrong.\n\nSo it\'s no surprise that more than a third of the money British taxpayers paid for the monarchy, led by Queen Elizabeth II, was spent on repairs, improvements and maintenance of aging but still opulent palaces.\n\n"We continue to focus on value for money," said Keeper of the Privy Purse Alan Reid, asserting that careful spending habits had allowed for more money to be used for important maintenance work.\n\n\nFILE - In this Saturday, June 14, 2014 file photo, Britain\'s Queen Elizabeth II, foreground, sur …\nA big part of the fixer-upper budget in the 12 months that ended on March 31 went to creating a suitable home for the young family of Prince William, his wife Kate and their toddler Prince George.\n\nSome 3.4 million pounds of taxpayer funds were used to refurbish part of London\'s Kensington Palace for the couple. The extensive work included removing asbestos, installing new heating and redecorating.\n\nThe couple, who have considerable personal financial resources in part because of the estate left by Princess Diana, paid for the carpets, curtains and furniture out of personal funds, the palace said.\n\nIn addition, Prince Charles\' private secretary, William Nye, suggested that Charles and his wife Camilla — who are supported by profits from the extensive Duchy of Cornwall estate — may have helped William and Kate set up their new home.\n\nThe palace accounts also showed the high cost of entertaining on a royal scale: 2 million pounds were spent on "housekeeping and hospitality" in the 12 months that ended on March 31.\n\nThat became evident when the Buckingham Palace released its accounts Thursday, which showed the monarchy cost British taxpayers 35.7 million pounds ($60.8 million) last year — 56 pence (just under $1) for everyone in the country.\n\nThat is 7.2 percent, or 2.4 million pounds, more than the year before and the increase is mainly explained by the British royal family\'s repair bills.\n\nTheir properties are hardly typical. Buckingham Palace, for example, has 240 bedrooms and 78 bathrooms. That\'s a lot of plumbing to fix when things go wrong. \n\nSo it\'s no surprise that more than a third of the money British taxpayers paid for the monarchy, led by Queen Elizabeth II, was spent on repairs, improvements and maintenance of aging but still opulent palaces.\n\n"We continue to focus on value for money," said Keeper of the Privy Purse Alan Reid, asserting that careful spending habits had allowed for more money to be used for important maintenance work\n\nThat became evident when the Buckingham Palace released its accounts Thursday, which showed the monarchy cost British taxpayers 35.7 million pounds ($60.8 million) last year — 56 pence (just under $1) for everyone in the country.\n\nThat is 7.2 percent, or 2.4 million pounds, more than the year before and the increase is mainly explained by the British royal family\'s repair bills.\n\nTheir properties are hardly typical. Buckingham Palace, for example, has 240 bedrooms and 78 bathrooms. That\'s a lot of plumbing to fix when things go wrong. \n\nSo it\'s no surprise that more than a third of the money British taxpayers paid for the monarchy, led by Queen Elizabeth II, was spent on repairs, improvements and maintenance of aging but still opulent palaces.\n\n"We continue to focus on value for money," said Keeper of the Privy Purse Alan Reid, asserting that careful spending habits had allowed for more money to be used for important maintenance work\n\n\nThat became evident when the Buckingham Palace released its accounts Thursday, which showed the monarchy cost British taxpayers 35.7 million pounds ($60.8 million) last year — 56 pence (just under $1) for everyone in the country.\n\nThat is 7.2 percent, or 2.4 million pounds, more than the year before and the increase is mainly explained by the British royal family\'s repair bills.\n\nTheir properties are hardly typical. Buckingham Palace, for example, has 240 bedrooms and 78 bathrooms. That\'s a lot of plumbing to fix when things go wrong. \n\nSo it\'s no surprise that more than a third of the money British taxpayers paid for the monarchy, led by Queen Elizabeth II, was spent on repairs, improvements and maintenance of aging but still opulent palaces.\n\n"We continue to focus on value for money," said Keeper of the Privy Purse Alan Reid, asserting that careful spending habits had allowed for more money to be used for important maintenance work\n\nThat became evident when the Buckingham Palace released its accounts Thursday, which showed the monarchy cost British taxpayers 35.7 million pounds ($60.8 million) last year — 56 pence (just under $1) for everyone in the country.\n\nThat is 7.2 percent, or 2.4 million pounds, more than the year before and the increase is mainly explained by the British royal family\'s repair bills.\n\nTheir properties are hardly typical. Buckingham Palace, for example, has 240 bedrooms and 78 bathrooms. That\'s a lot of plumbing to fix when things go wrong. \n\nSo it\'s no surprise that more than a third of the money British taxpayers paid for the monarchy, led by Queen Elizabeth II, was spent on repairs, improvements and maintenance of aging but still opulent palaces.\n\n"We continue to focus on value for money," said Keeper of the Privy Purse Alan Reid, asserting that careful spending habits had allowed for more money to be used for important maintenance work\n---ending ---\n\n' | ||
note.trim(); | ||
expect(note.length()).to.equal(2048); | ||
}); | ||
describe("aps payload", function() { | ||
describe("getAlertText", function() { | ||
describe("plain alert string", function() { | ||
it("gets the alert text", function() { | ||
note.alert = "hello"; | ||
it("should trim long alert bodies ", function () { | ||
note.alert = { | ||
body: 'ㅂㅈ ㅐ: LONDON (AP) — E\\\veryone says there areare lots of hidden costs to owning a home. If you own a palace, the costs are royal.\n\nThat became evident when the Buckingham Palace released its accounts Thursday, which showed the monarchy cost British taxpayers 35.7 million pounds ($60.8 million) last year — 56 pence (just under $1) for everyone in the country.\n\nThat is 7.2 percent, or 2.4 million pounds, more than the year before and the increase is mainly explained by the British royal family\'s repair bills.\n\nTheir properties are hardly typical. Buckingham Palace, for example, has 240 bedrooms and 78 bathrooms. That\'s a lot of plumbing to fix when things go wrong.\n\nSo it\'s no surprise that more than a third of the money British taxpayers paid for the monarchy, led by Queen Elizabeth II, was spent on repairs, improvements and maintenance of aging but still opulent palaces.\n\n"We continue to focus on value for money," said Keeper of the Privy Purse Alan Reid, asserting that careful spending habits had allowed for more money to be used for important maintenance work.\n\n\nFILE - In this Saturday, June 14, 2014 file photo, Britain\'s Queen Elizabeth II, foreground, sur …\nA big part of the fixer-upper budget in the 12 months that ended on March 31 went to creating a suitable home for the young family of Prince William, his wife Kate and their toddler Prince George.\n\nSome 3.4 million pounds of taxpayer funds were used to refurbish part of London\'s Kensington Palace for the couple. The extensive work included removing asbestos, installing new heating and redecorating.\n\nThe couple, who have considerable personal financial resources in part because of the estate left by Princess Diana, paid for the carpets, curtains and furniture out of personal funds, the palace said.\n\nIn addition, Prince Charles\' private secretary, William Nye, suggested that Charles and his wife Camilla — who are supported by profits from the extensive Duchy of Cornwall estate — may have helped William and Kate set up their new home.\n\nThe palace accounts also showed the high cost of entertaining on a royal scale: 2 million pounds were spent on "housekeeping and hospitality" in the 12 months that ended on March 31.\n\nThat became evident when the Buckingham Palace released its accounts Thursday, which showed the monarchy cost British taxpayers 35.7 million pounds ($60.8 million) last year — 56 pence (just under $1) for everyone in the country.\n\nThat is 7.2 percent, or 2.4 million pounds, more than the year before and the increase is mainly explained by the British royal family\'s repair bills.\n\nTheir properties are hardly typical. Buckingham Palace, for example, has 240 bedrooms and 78 bathrooms. That\'s a lot of plumbing to fix when things go wrong. \n\nSo it\'s no surprise that more than a third of the money British taxpayers paid for the monarchy, led by Queen Elizabeth II, was spent on repairs, improvements and maintenance of aging but still opulent palaces.\n\n"We continue to focus on value for money," said Keeper of the Privy Purse Alan Reid, asserting that careful spending habits had allowed for more money to be used for important maintenance work\n\nThat became evident when the Buckingham Palace released its accounts Thursday, which showed the monarchy cost British taxpayers 35.7 million pounds ($60.8 million) last year — 56 pence (just under $1) for everyone in the country.\n\nThat is 7.2 percent, or 2.4 million pounds, more than the year before and the increase is mainly explained by the British royal family\'s repair bills.\n\nTheir properties are hardly typical. Buckingham Palace, for example, has 240 bedrooms and 78 bathrooms. That\'s a lot of plumbing to fix when things go wrong. \n\nSo it\'s no surprise that more than a third of the money British taxpayers paid for the monarchy, led by Queen Elizabeth II, was spent on repairs, improvements and maintenance of aging but still opulent palaces.\n\n"We continue to focus on value for money," said Keeper of the Privy Purse Alan Reid, asserting that careful spending habits had allowed for more money to be used for important maintenance work\n\n\nThat became evident when the Buckingham Palace released its accounts Thursday, which showed the monarchy cost British taxpayers 35.7 million pounds ($60.8 million) last year — 56 pence (just under $1) for everyone in the country.\n\nThat is 7.2 percent, or 2.4 million pounds, more than the year before and the increase is mainly explained by the British royal family\'s repair bills.\n\nTheir properties are hardly typical. Buckingham Palace, for example, has 240 bedrooms and 78 bathrooms. That\'s a lot of plumbing to fix when things go wrong. \n\nSo it\'s no surprise that more than a third of the money British taxpayers paid for the monarchy, led by Queen Elizabeth II, was spent on repairs, improvements and maintenance of aging but still opulent palaces.\n\n"We continue to focus on value for money," said Keeper of the Privy Purse Alan Reid, asserting that careful spending habits had allowed for more money to be used for important maintenance work\n\nThat became evident when the Buckingham Palace released its accounts Thursday, which showed the monarchy cost British taxpayers 35.7 million pounds ($60.8 million) last year — 56 pence (just under $1) for everyone in the country.\n\nThat is 7.2 percent, or 2.4 million pounds, more than the year before and the increase is mainly explained by the British royal family\'s repair bills.\n\nTheir properties are hardly typical. Buckingham Palace, for example, has 240 bedrooms and 78 bathrooms. That\'s a lot of plumbing to fix when things go wrong. \n\nSo it\'s no surprise that more than a third of the money British taxpayers paid for the monarchy, led by Queen Elizabeth II, was spent on repairs, improvements and maintenance of aging but still opulent palaces.\n\n"We continue to focus on value for money," said Keeper of the Privy Purse Alan Reid, asserting that careful spending habits had allowed for more money to be used for important maintenance work\n---ending ---\n\n' | ||
}; | ||
note.trim(); | ||
expect(note.length()).to.equal(2048); | ||
}); | ||
expect(note.getAlertText()).to.equal("hello"); | ||
}); | ||
}); | ||
it("should trim long messages with escaped characters", function () { | ||
note.alert = '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'; | ||
note.trim(256); | ||
expect(note.length()).to.equal(256); | ||
describe("alert object", function() { | ||
it("gets the alert text", function() { | ||
note.alert = { "body": "hello" }; | ||
expect(note.getAlertText()).to.equal("hello"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it("should trim long messages with escaped characters by chopping off the last backslash", function () { | ||
note.alert = ' \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'; | ||
note.trim(256); | ||
expect(note.length()).to.equal(255); | ||
describe("length", function() { | ||
it("returns the correct payload length", function() { | ||
note.alert = "length"; | ||
expect(note.length()).to.equal(26); | ||
}); | ||
describe("payload changes after first calculation", function() { | ||
beforeEach(function() { | ||
note.alert = "short"; | ||
note.length(); | ||
}); | ||
it("returns the correct payload length", function() { | ||
note.alert = "longer"; | ||
expect(note.length()).to.equal(26); | ||
}); | ||
}); | ||
}); | ||
it("should trim long messages with uni characters", function () { | ||
note.alert = 'ㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐ'; | ||
note.trim(256); | ||
expect(note.length()).to.be.at.most(256); | ||
describe("compile", function() { | ||
var stub; | ||
beforeEach(function() { | ||
stub = sinon.stub(note, "toJSON"); | ||
}); | ||
it("compiles the JSON payload", function() { | ||
stub.returns("payload"); | ||
expect(note.compile()).to.equal("\"payload\""); | ||
}); | ||
it("returns the JSON payload", function() { | ||
stub.returns({}); | ||
expect(note.compile()).to.equal("{}"); | ||
}); | ||
it("memoizes the JSON payload", function() { | ||
stub.returns("payload1"); | ||
note.compile(); | ||
stub.returns("payload2"); | ||
expect(note.compile()).to.equal("\"payload1\""); | ||
}); | ||
it("re-compiles the JSON payload when `note.compiled` = false", function() { | ||
stub.returns("payload1"); | ||
note.compile(); | ||
stub.returns("payload2"); | ||
note.compiled = false; | ||
expect(note.compile()).to.equal("\"payload2\""); | ||
}); | ||
}); | ||
it("should trim long messages with unprintible characters", function () { | ||
note.alert = '\x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07\x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07\x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07\x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07\x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07\x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07\x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07\x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07\x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07\x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07\x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07 \x07'; | ||
note.trim(256); | ||
expect(note.length()).to.be.at.most(256); | ||
describe("trim", function() { | ||
var longText = 'ㅂㅈ ㅐ: LONDON (AP) — E\\\veryone says there areare lots of hidden costs to owning a home. If you own a palace, the costs are royal.\n\nThat became evident when the Buckingham Palace released its accounts Thursday, which showed the monarchy cost British taxpayers 35.7 million pounds ($60.8 million) last year — 56 pence (just under $1) for everyone in the country.\n\nThat is 7.2 percent, or 2.4 million pounds, more than the year before and the increase is mainly explained by the British royal family\'s repair bills.\n\nTheir properties are hardly typical. Buckingham Palace, for example, has 240 bedrooms and 78 bathrooms. That\'s a lot of plumbing to fix when things go wrong.\n\nSo it\'s no surprise that more than a third of the money British taxpayers paid for the monarchy, led by Queen Elizabeth II, was spent on repairs, improvements and maintenance of aging but still opulent palaces.\n\n"We continue to focus on value for money," said Keeper of the Privy Purse Alan Reid, asserting that careful spending habits had allowed for more money to be used for important maintenance work.\n\n\nFILE - In this Saturday, June 14, 2014 file photo, Britain\'s Queen Elizabeth II, foreground, sur …\nA big part of the fixer-upper budget in the 12 months that ended on March 31 went to creating a suitable home for the young family of Prince William, his wife Kate and their toddler Prince George.\n\nSome 3.4 million pounds of taxpayer funds were used to refurbish part of London\'s Kensington Palace for the couple. The extensive work included removing asbestos, installing new heating and redecorating.\n\nThe couple, who have considerable personal financial resources in part because of the estate left by Princess Diana, paid for the carpets, curtains and furniture out of personal funds, the palace said.\n\nIn addition, Prince Charles\' private secretary, William Nye, suggested that Charles and his wife Camilla — who are supported by profits from the extensive Duchy of Cornwall estate — may have helped William and Kate set up their new home.\n\nThe palace accounts also showed the high cost of entertaining on a royal scale: 2 million pounds were spent on "housekeeping and hospitality" in the 12 months that ended on March 31.\n---ending ---\n\n'; | ||
describe("with default length", function() { | ||
it("trims notification text to reduce payload to maximum length", function () { | ||
note.alert = longText | ||
note.trim(); | ||
expect(note.length()).to.equal(2048); | ||
}); | ||
it("trims notification alert body to reduce payload to maximum length", function () { | ||
note.alert = { | ||
body: longText | ||
}; | ||
note.trim(); | ||
expect(note.length()).to.equal(2048); | ||
}); | ||
}); | ||
describe("with specified length", function() { | ||
it("trims correctly", function() { | ||
note.alert = "12345"; | ||
var trimLength = note.length() - 2; | ||
note.trim(trimLength); | ||
expect(note.length()).to.equal(trimLength); | ||
}); | ||
it("trims to length longer than default", function() { | ||
note.alert = longText + longText; | ||
var trimLength = 4096; | ||
note.trim(trimLength); | ||
expect(note.length()).to.equal(4096); | ||
}); | ||
}) | ||
describe("alert with escape sequences", function() { | ||
it("strips correctly", function () { | ||
note.alert = "\n\n\n"; | ||
var trimLength = note.length() - 2; | ||
note.trim(trimLength); | ||
expect(note.length()).to.equal(trimLength); | ||
}); | ||
it("strips trailing escape characters", function () { | ||
note.alert = "\n\n\n"; | ||
var trimLength = note.length() - 1; | ||
note.trim(trimLength); | ||
var lastChar = note.alert[note.alert.length - 1]; | ||
expect(lastChar).to.not.equal("\\"); | ||
}); | ||
}); | ||
describe("unicode text", function() { | ||
it("trims to maximum byte length", function () { | ||
note.alert = "ㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐㅂㅈ ㅐ"; | ||
note.trim(256); | ||
expect(note.length()).to.be.at.most(256); | ||
}); | ||
describe("with UTF-8 encoding", function() { | ||
it("removes trailing `REPLACEMENT CHARACTER` 0xFFFD", function() { | ||
note.alert = Buffer([0xF0, 0x9F, 0x98, 0x83, 0xF0, 0x9F, 0x98, 0x9E]).toString("utf8"); | ||
var trimLength = note.length() - 1; | ||
note.trim(trimLength); | ||
var length = note.alert.length; | ||
expect(note.alert.charCodeAt(length - 1)).to.not.equal(0xFFFD); | ||
}); | ||
}); | ||
describe("with UTF-16LE encoding", function() { | ||
it("correctly empties the string", function() { | ||
note.encoding = "utf16le"; | ||
note.alert = Buffer([0x3D, 0xD8, 0x03, 0xDE, 0x3D, 0xD8, 0x1E, 0xDE]).toString(note.encoding); | ||
var trimLength = note.length() - 8; | ||
note.trim(trimLength); | ||
expect(note.alert.length).to.equal(0); | ||
}); | ||
it("removes orphaned lead surrogates", function() { | ||
note.encoding = "utf16le"; | ||
note.alert = Buffer([0x3D, 0xD8, 0x03, 0xDE, 0x3D, 0xD8, 0x1E, 0xDE]).toString(note.encoding); | ||
var trimLength = note.length() - 2; | ||
note.trim(trimLength); | ||
var length = note.alert.length; | ||
expect(note.alert.charCodeAt(length - 1)).to.not.be.within(0xD800, 0xD8FF); | ||
}); | ||
}); | ||
describe("escape sequences", function() { | ||
it("removes sequence without digits", function() { | ||
note.alert = '\u0006\u0007'; | ||
var trimLength = note.length() - 4; | ||
note.trim(trimLength); | ||
expect(note.alert.length).to.equal(1); | ||
}); | ||
it("removes sequence with fewer than 4 digits", function() { | ||
note.alert = '\u0006\u0007'; | ||
var trimLength = note.length() - 3; | ||
note.trim(trimLength); | ||
expect(note.alert.length).to.equal(1); | ||
}); | ||
it("does not remove a complete sequence", function() { | ||
note.alert = '\u0006\u0007 '; | ||
var trimLength = note.length() - 1; | ||
note.trim(trimLength); | ||
expect(note.alert.charCodeAt(1)).to.equal(7); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
3375
26
227565
+ Addedq@1.5.1(transitive)
- Removedq@1.1.2(transitive)
Updatedq@>1.1.0 < 2.0.0