Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ~ to allowed operators #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "rfc6570",
"main": "rfc6570.js",
"version": "0.1.9",
"ignore": [
"**/.*",
"node_modules",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"mocha": "^1.20.1",
"mocha-lcov-reporter": "0.0.1"
},
"version": "0.1.8",
"version": "0.1.9",
"dependencies": {
"mocha-lcov-reporter": "0.0.1"
},
Expand Down
11 changes: 6 additions & 5 deletions rfc6570.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var operatorOptions = {
"prefix": "/",
"seperator": "/",
"assignment": false,
"assignEmpty": false,
"encode": encodeURIComponent
},
";": {
Expand Down Expand Up @@ -142,22 +143,22 @@ function UriTemplate(template) {
op-level3 = "." / "/" / ";" / "?" / "&"
op-reserve = "=" / "," / "!" / "@" / "|"
*/
var reTemplate = /\{([\+#\.\/;\?&=\,!@\|]?)([A-Za-z0-9_\,\.\:\*]+?)\}/g;
var reVariable = /^([\$_a-z][\$_a-z0-9]*)((?:\:[1-9][0-9]?[0-9]?[0-9]?)?)(\*?)$/i;
var reTemplate = /\{([\+#\.\/;\?&=\,!@\|]?)([A-Za-z0-9_\,\.\:\*\~]+?)\}/g;
var reVariable = /^([\$_a-z][\$_a-z0-9~]*)((?:\:[1-9][0-9]?[0-9]?[0-9]?)?)(\*?)$/i;
var match;
var pieces = [];
var glues = [];
var offset = 0;
var pieceCount = 0;

while ( !! (match = reTemplate.exec(template))) {
while (!!(match = reTemplate.exec(template))) {
glues.push(template.substring(offset, match.index));
/*
The operator characters equals ("="), comma (","), exclamation ("!"),
at sign ("@"), and pipe ("|") are reserved for future extensions.
*/
if (match[1] && ~'=,!@|'.indexOf(match[1])) {
throw "operator '" + match[1] + "' is reserved for future extensions";
throw new Error("operator '" + match[1] + "' is reserved for future extensions");
}

offset = match.index;
Expand All @@ -174,7 +175,7 @@ function UriTemplate(template) {
return {
name: match[1],
maxLength: match[2] && parseInt(match[2].substring(1), 10),
composite: !! match[3]
composite: !!match[3]
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/UriTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ function UriTemplate(template) {
op-level3 = "." / "/" / ";" / "?" / "&"
op-reserve = "=" / "," / "!" / "@" / "|"
*/
var reTemplate = /\{([\+#\.\/;\?&=\,!@\|]?)([A-Za-z0-9_\,\.\:\*]+?)\}/g;
var reVariable = /^([\$_a-z][\$_a-z0-9]*)((?:\:[1-9][0-9]?[0-9]?[0-9]?)?)(\*?)$/i;
var reTemplate = /\{([\+#\.\/;\?&=\,!@\|]?)([A-Za-z0-9_\,\.\:\*\~]+?)\}/g;
var reVariable = /^([\$_a-z][\$_a-z0-9~]*)((?:\:[1-9][0-9]?[0-9]?[0-9]?)?)(\*?)$/i;
var match;
var pieces = [];
var glues = [];
Expand Down
1 change: 1 addition & 0 deletions test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Router', function () {
router.add('/a/b/{c}/{d}', setLastRouteData);
router.add('/a/b/{c}', setLastRouteData);
router.add('/a/b{?c,d}', setLastRouteData);
router.add('/a/b{?c,d~}', setLastRouteData);

it('test 1', function () {
router.handle('/a/b/1');
Expand Down