Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #411 from s3u/master

Fix 409
  • Loading branch information...
commit f1d245978293ac205c245ba1e1d9ff9ca06ffb62 2 parents 617323c + 31178e3
@shimonchayim shimonchayim authored
View
4 CHANGES.md
@@ -1,3 +1,7 @@
+## Mar 29, 2012
+
+* Fix regression in uri-template formatter (https://github.com/ql-io/ql.io/issues/409).
+
## Mar 28, 2012
* Upgrade cluster2, and also pass ecvPath to cluster2
View
2  modules/uri-template/lib/uri-template.js
@@ -191,7 +191,7 @@ module.exports = (function(){
var encode = !ele.dontencode;
if(val.constructor == Array) {
// But is the token multivalued?
- if(val.length === 0) {
+ if(val.length === 0 && ele.required) {
throw {
error: 'Token ' + ele.variable + ' not specified. Processed ' + str
}
View
2  modules/uri-template/package.json
@@ -2,7 +2,7 @@
"author": "ql.io",
"description": "A small URI template processor for ql.io.",
"name": "ql.io-uri-template",
- "version": "0.4.5",
+ "version": "0.4.6",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
View
2  modules/uri-template/peg/uri-template.peg
@@ -80,7 +80,7 @@ URITemplate = c:( literal / expression )* {
var encode = !ele.dontencode;
if(val.constructor == Array) {
// But is the token multivalued?
- if(val.length === 0) {
+ if(val.length === 0 && ele.required) {
throw {
error: 'Token ' + ele.variable + ' not specified. Processed ' + str
}
View
19 modules/uri-template/test/uri-template-test.js
@@ -266,6 +266,25 @@ module.exports = {
test.done();
},
+ 'multivalued-optional': function (test) {
+ var str = 'https://www.example.org/path1/path2?p1={0|v1}&p2={0|v2}&p3={0|v3}';
+ var template = uriTemplate.parse(str);
+ try {
+ var uri = template.format({
+ v1: [],
+ v2: [],
+ v3: '1,2,3,4'
+ });
+ test.equals(uri, 'https://www.example.org/path1/path2?p1=&p2=&p3=1%2C2%2C3%2C4');
+ test.done();
+ }
+ catch(e) {
+ console.log(e.stack || e);
+ test.ok(false, 'Not expected to fail');
+ test.done();
+ }
+ },
+
'encode': function(test) {
var str = 'http://www.foo.com?p1={p1}&p2={p2}&p3={5|p3}';
var template = uriTemplate.parse(str);
Please sign in to comment.
Something went wrong with that request. Please try again.