Escaping key value interpolation #1
This commit is contained in:
parent
3a69f3bd20
commit
8d65af5ff7
2 changed files with 23 additions and 6 deletions
|
|
@ -72,4 +72,18 @@ describe('Kiwi.compose - %{}', function() {
|
||||||
var output = "The quick brown jumps over the lazy dog.";
|
var output = "The quick brown jumps over the lazy dog.";
|
||||||
expect(Kiwi.compose(input, dic)).toEqual(output);
|
expect(Kiwi.compose(input, dic)).toEqual(output);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should escape key value interpolation if ` is given before %',function() {
|
||||||
|
var input = "The quick brown `%{f} jumps over the lazy dog.";
|
||||||
|
var dic = {"d": "dog"};
|
||||||
|
var output = "The quick brown %{f} jumps over the lazy dog.";
|
||||||
|
expect(Kiwi.compose(input, dic)).toEqual(output);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should escape key value interpolation for the first case but not for the 2nd.',function() {
|
||||||
|
var input = "The quick brown `%{f} %{f} jumps over the lazy dog.";
|
||||||
|
var dic = {"f": "fox"};
|
||||||
|
var output = "The quick brown %{f} fox jumps over the lazy dog.";
|
||||||
|
expect(Kiwi.compose(input, dic)).toEqual(output);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -56,7 +56,10 @@ var Kiwi = (function ($) {
|
||||||
var nextChar = null;
|
var nextChar = null;
|
||||||
if(i + 1 < length) nextChar = text[i+1];
|
if(i + 1 < length) nextChar = text[i+1];
|
||||||
|
|
||||||
if(currentChar === '%' && nextChar === '{'){
|
if (currentChar === '`' && nextChar === '%') {
|
||||||
|
stringToReturn += '%';
|
||||||
|
i += 1;
|
||||||
|
}else if(currentChar === '%' && nextChar === '{'){
|
||||||
var result = get_key_length(text, i);
|
var result = get_key_length(text, i);
|
||||||
var key = result[0];
|
var key = result[0];
|
||||||
var key_length = result[1];
|
var key_length = result[1];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue