Skip to content

Commit 67e6916

Browse files
authored
Merge pull request #72 from bookernath/fix-json-safestring
Fix json helper to work with a nested getImage helper
2 parents ad337de + 0ffd5a1 commit 67e6916

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

helpers/json.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
'use strict';
2+
const SafeString = require('handlebars').SafeString;
23

34
const factory = () => {
45
return function(data) {
6+
if (data instanceof SafeString) {
7+
data = data.toString();
8+
}
59
return JSON.stringify(data);
610
};
711
};

spec/helpers/json.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ const Lab = require('lab'),
55
testRunner = require('../spec-helpers').testRunner;
66

77
describe('json helper', function() {
8+
const urlData_2_qs = 'https://cdn.example.com/path/to/{:size}/image.png?c=2&imbypass=on';
89
const context = {
10+
image_with_2_qs: {
11+
data: urlData_2_qs
12+
},
913
object: { a: 1, b: "hello" }
1014
};
1115

@@ -19,4 +23,12 @@ describe('json helper', function() {
1923
},
2024
], done);
2125
});
26+
it('should work together with getImage', function(done) {
27+
runTestCases([
28+
{
29+
input: '{{{json (getImage image_with_2_qs)}}}',
30+
output: '"https://cdn.example.com/path/to/original/image.png?c=2&imbypass=on"',
31+
},
32+
], done);
33+
});
2234
});

0 commit comments

Comments
 (0)