Skip to content

Commit

Permalink
Merge pull request #287 from keanu-delgado/patch-1
Browse files Browse the repository at this point in the history
fix(template): allow periods in the variable name
  • Loading branch information
rodneyrehm committed Mar 24, 2016
2 parents c9c395d + d11373d commit 670ea0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/URITemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@
// pattern to identify expressions [operator, variable-list] in template
URITemplate.EXPRESSION_PATTERN = /\{([^a-zA-Z0-9%_]?)([^\}]+)(\}|$)/g;
// pattern to identify variables [name, explode, maxlength] in variable-list
URITemplate.VARIABLE_PATTERN = /^([^*:]+)((\*)|:(\d+))?$/;
URITemplate.VARIABLE_PATTERN = /^([^*:.](?:\.?[^*:.])*)((\*)|:(\d+))?$/;
// pattern to verify variable name integrity
URITemplate.VARIABLE_NAME_PATTERN = /[^a-zA-Z0-9%_]/;
URITemplate.VARIABLE_NAME_PATTERN = /[^a-zA-Z0-9%_.]/;

// expand parsed expression (expression, not template!)
URITemplate.expand = function(expression, data) {
Expand Down
8 changes: 8 additions & 0 deletions test/test_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,12 @@
window.URITemplate = actual_lib;
});

test('Periods in varnames', function() {
var template = new URITemplate('{hello.world.var}');
var literal = 'replacement'
var data = {'hello.world.var': literal};
var expansion = template.expand(data);
equal(expansion, literal, 'period in varname');
});

})();

0 comments on commit 670ea0d

Please sign in to comment.