@port-labs/jq-node-bindings 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/template.js CHANGED
@@ -8,8 +8,12 @@ const findInsideDoubleBracesIndices = (input) => {
8
8
  for (let i = 0; i < input.length; i += 1) {
9
9
  const char = input[i];
10
10
 
11
- if (char === '"' || char === "'") {
12
- // If inside quotes, ignore braces
11
+ if (insideDoubleBracesStart && char === '\\') {
12
+ // If next character is escaped, skip it
13
+ i += 1;
14
+ }
15
+ if (insideDoubleBracesStart && (char === '"' || char === "'")) {
16
+ // If inside double braces and inside quotes, ignore braces
13
17
  if (!wrappingQuote) {
14
18
  wrappingQuote = char;
15
19
  } else if (wrappingQuote === char) {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@port-labs/jq-node-bindings",
3
- "version": "v0.0.9",
3
+ "version": "v0.0.10",
4
4
  "description": "Node.js bindings for JQ",
5
- "jq-node-bindings": "0.0.9",
5
+ "jq-node-bindings": "0.0.10",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {
8
8
  "configure": "node-gyp configure",
@@ -136,5 +136,18 @@ describe('template', () => {
136
136
  expect(render([{'{{.bar}}': [false, '/foo/{{.foo + .bar}}']}])).toEqual([{foo: [false, '/foo/barfoo']}]);
137
137
  expect(render({foo: [{bar: '{{1}}'}, '{{empty}}']})).toEqual({foo: [{bar: 1}, undefined]});
138
138
  });
139
+ it('should accept quotes outside of template', () => {
140
+ const json = { foo: 'bar', bar: 'foo' };
141
+ const render = (input) => jq.renderRecursively(json, input);
142
+
143
+ expect(render('"{{.foo}}"')).toEqual('"bar"');
144
+ expect(render('\'{{.foo}}\'')).toEqual('\'bar\'');
145
+ });
146
+ it('should accept escaped quotes inside jq template', () => {
147
+ const json = { foo: 'bar', bar: 'foo' };
148
+ const render = (input) => jq.renderRecursively(json, input);
149
+
150
+ expect(render('{{"\\"foo\\""}}')).toEqual('"foo"');
151
+ });
139
152
  })
140
153