4 Commits

Author SHA1 Message Date
James Coglan 2af2c18251 Bump version to 0.1.3. 2017-11-11 01:24:29 +00:00
James Coglan 50bcedda78 Test on Node v9. 2017-11-11 01:05:57 +00:00
James Coglan e3aa5246d6 Avoid errors caused by extension names or parameters having names that clash with things in Object.prototype. 2017-11-11 00:45:16 +00:00
James Coglan 1e58c148cb Header parser should accept uppercase letters. 2017-11-11 00:44:44 +00:00
5 changed files with 26 additions and 5 deletions
+1
View File
@@ -10,6 +10,7 @@ node_js:
- "6"
- "7"
- "8"
- "9"
before_install:
- '[ "${TRAVIS_NODE_VERSION}" = "0.8" ] && npm install -g npm@~1.4.0 || true'
+5
View File
@@ -1,3 +1,8 @@
### 0.1.3 / 2017-11-11
* Accept extension names and parameters including uppercase letters
* Handle extension names that clash with `Object.prototype` properties
### 0.1.2 / 2017-09-10
* Catch synchronous exceptions thrown when calling an extension
+8 -4
View File
@@ -1,13 +1,15 @@
'use strict';
var TOKEN = /([!#\$%&'\*\+\-\.\^_`\|~0-9a-z]+)/,
NOTOKEN = /([^!#\$%&'\*\+\-\.\^_`\|~0-9a-z])/g,
var TOKEN = /([!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+)/,
NOTOKEN = /([^!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z])/g,
QUOTED = /"((?:\\[\x00-\x7f]|[^\x00-\x08\x0a-\x1f\x7f"])*)"/,
PARAM = new RegExp(TOKEN.source + '(?:=(?:' + TOKEN.source + '|' + QUOTED.source + '))?'),
EXT = new RegExp(TOKEN.source + '(?: *; *' + PARAM.source + ')*', 'g'),
EXT_LIST = new RegExp('^' + EXT.source + '(?: *, *' + EXT.source + ')*$'),
NUMBER = /^-?(0|[1-9][0-9]*)(\.[0-9]+)?$/;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var Parser = {
parseHeader: function(header) {
var offers = new Offers();
@@ -35,7 +37,7 @@ var Parser = {
}
if (NUMBER.test(data)) data = parseFloat(data);
if (offer.hasOwnProperty(key)) {
if (hasOwnProperty.call(offer, key)) {
offer[key] = [].concat(offer[key]);
offer[key].push(data);
} else {
@@ -77,7 +79,9 @@ var Offers = function() {
};
Offers.prototype.push = function(name, params) {
this._byName[name] = this._byName[name] || [];
if (!hasOwnProperty.call(this._byName, name))
this._byName[name] = [];
this._byName[name].push(params);
this._inOrder.push({name: name, params: params});
};
+1 -1
View File
@@ -5,7 +5,7 @@
, "keywords" : ["websocket"]
, "license" : "MIT"
, "version" : "0.1.2"
, "version" : "0.1.3"
, "engines" : { "node": ">=0.8.0" }
, "files" : ["lib"]
, "main" : "./lib/websocket_extensions"
+11
View File
@@ -67,6 +67,17 @@ test.describe("Parser", function() { with(this) {
{name: "a", params: {b: true}}],
parse('a; b=1, c, b; d, c; e="hi, there"; e, a; b') )
}})
it("parses an extension name that shadows an Object property", function() { with(this) {
assertEqual( [{name: "hasOwnProperty", params: {}}],
parse('hasOwnProperty') )
}})
it("parses an extension param that shadows an Object property", function() { with(this) {
var result = parse('foo; hasOwnProperty; x')[0]
assertEqual( result.params.hasOwnProperty, true )
}})
}})
describe("serializeParams", function() { with(this) {