Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2af2c18251 | |||
| 50bcedda78 | |||
| e3aa5246d6 | |||
| 1e58c148cb |
@@ -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'
|
||||
|
||||
@@ -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
@@ -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
@@ -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"
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user