Skip to content

Commit 9db822c

Browse files
authored
Merge pull request #92 from bookernath/replace-safestring
Allow replace helper to handle safestrings
2 parents 2244238 + 46edb7d commit 9db822c

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

helpers/replace.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use strict';
2+
const common = require('./lib/common.js');
23

34
const factory = () => {
45
return function(needle, haystack) {
6+
needle = common.unwrapIfSafeString(needle);
7+
haystack = common.unwrapIfSafeString(haystack);
58
const options = arguments[arguments.length - 1];
69

710
if (typeof needle !== 'string') {

spec/helpers/replace.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('replace helper', function() {
1212
const context = {
1313
content: "Either you run the %%var%% or the %%var%% runs you",
1414
price: '$49.99',
15+
facet: 'brand',
1516
};
1617

1718
const runTestCases = testRunner({context, templates});
@@ -52,6 +53,15 @@ describe('replace helper', function() {
5253
], done);
5354
});
5455

56+
it('should work nicely with other helpers that use safestring', function(done) {
57+
runTestCases([
58+
{
59+
input: "Replace+Concat+Hyphenated: fifth-{{#replace '&' (concat '&' (hyphenate facet)) }}{{/replace}}",
60+
output: "Replace+Concat+Hyphenated: fifth-brand",
61+
},
62+
], done);
63+
});
64+
5565
it('should gracefully handle not strings', function(done) {
5666
runTestCases([
5767
{

0 commit comments

Comments
 (0)