Skip to content

Commit

Permalink
Merge pull request #290 from keanu-delgado/patch-3
Browse files Browse the repository at this point in the history
Disallow prefix modifier on variables with composite values
  • Loading branch information
rodneyrehm committed Mar 30, 2016
2 parents d37c326 + aae197e commit ffd9b33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/URITemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@
continue;
}

if (d.type > 1 && variable.maxlength) {
// composite variable cannot specify maxlength
throw new Error('Invalid expression: Prefix modifier not applicable to variable "' + variable.name + '"');
}

// expand the given variable
buffer.push(URITemplate['expand' + type](
d,
Expand Down
7 changes: 7 additions & 0 deletions test/test_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@
}, Error, 'Failing invalid modifier');
});

test('Expansion errors', function() {
raises(function() {
var data = {'composite_var': ['multiple', 'values']};
URITemplate('{composite_var:3}').expand(data);
}, Error, 'Failing prefix modifier after composite variable');
});

test('noConflict mode', function() {
var actual_lib = URITemplate; // actual library; after loading, before noConflict()
var unconflicted = URITemplate.noConflict();
Expand Down

0 comments on commit ffd9b33

Please sign in to comment.