Commit 104949aa authored by fxa's avatar fxa

fixed issue #1 wrong behaviour with ':'

parent b03daea2
...@@ -26,6 +26,13 @@ and then: ...@@ -26,6 +26,13 @@ and then:
template.expand({query: {first: 1, second: 2}}); template.expand({query: {first: 1, second: 2}});
--> "?first=1&second=2" --> "?first=1&second=2"
If you want to clone the git project, be aware of the submodule uritemplate-test.
So you have to to:
git https://github.com/fxa/uritemplate-js.git
git submodule init
git submodule update
Tests Tests
----- -----
......
{
"Jira bug #1" : {
"comment": "tests, whether the '://' can be passed",
"level": 1,
"variables": {
"q": "val"
},
"testcases" : [
["http://localhost:8080/api/search{?q}", "http://localhost:8080/api/search?q=val"]
]
}
}
...@@ -23,5 +23,5 @@ ...@@ -23,5 +23,5 @@
"uritemplate-test/spec-examples-by-sections.json", "uritemplate-test/spec-examples-by-sections.json",
"uritemplate-test/spec-examples.json" "uritemplate-test/spec-examples.json"
], ],
"version" : "0.1.2" "version" : "0.1.3"
} }
\ No newline at end of file
...@@ -32,6 +32,16 @@ ...@@ -32,6 +32,16 @@
} }
return currentValue; return currentValue;
} }
function arrayAll(array, predicate) {
var index;
for (index = 0; index < array.length; index += 1) {
if (!predicate(array[index], index, array)) {
return false;
}
}
return true;
}
function reduce(arrayOrObject, callback, initialValue) { function reduce(arrayOrObject, callback, initialValue) {
return isArray(arrayOrObject) ? arrayReduce(arrayOrObject, callback, initialValue) : objectReduce(arrayOrObject, callback, initialValue); return isArray(arrayOrObject) ? arrayReduce(arrayOrObject, callback, initialValue) : objectReduce(arrayOrObject, callback, initialValue);
...@@ -473,10 +483,10 @@ ...@@ -473,10 +483,10 @@
literalStart = null; literalStart = null;
braceOpenIndex = index; braceOpenIndex = index;
} }
// TODO check for allowed chars. This if-statement is just to pass the uritemplate-test // TODO if (chr === ';')
if (chr === ':' && uriTemplateText.substring(literalStart, index).indexOf('/') >= 0) { // In a regular URI a colon is only allowed as separator after a uri scheme (e.g. 'http:') and between host and port
throw new Error('":" not allowed after a "/" in a regular uri'); // (e.g. 'example.com:443'). So the only slash allowed in front of a colon is the '//' after the scheme separator
} // throw new Error('":" not allowed after a "/" in a regular uri');
continue; continue;
} }
......
...@@ -81,6 +81,8 @@ ...@@ -81,6 +81,8 @@
runTestFile('uritemplate-test/spec-examples.json'); runTestFile('uritemplate-test/spec-examples.json');
runTestFile('uritemplate-test/extended-tests.json'); runTestFile('uritemplate-test/extended-tests.json');
runTestFile('uritemplate-test/negative-tests.json'); runTestFile('uritemplate-test/negative-tests.json');
runTestFile('own-testcases.json');
console.log('passed all ' + numTestsPassed + ' tests!'); console.log('passed all ' + numTestsPassed + ' tests!');
}()); }());
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment