From 0f99d11e3995ad162518bccf6b29e472a4965bcf Mon Sep 17 00:00:00 2001 From: Nathan Booker Date: Fri, 5 Jun 2020 12:41:31 -0500 Subject: [PATCH] Allow replace helper to accept safestrings, release 2.0.24 --- helpers/replace.js | 4 ++++ package.json | 2 +- test/helpers/replace.js | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/helpers/replace.js b/helpers/replace.js index afce47ad..1708b53a 100644 --- a/helpers/replace.js +++ b/helpers/replace.js @@ -1,7 +1,11 @@ 'use strict'; +const common = require('../lib/common.js'); function helper(paper) { paper.handlebars.registerHelper('replace', function (needle, haystack) { + needle = common.unwrapIfSafeString(needle); + haystack = common.unwrapIfSafeString(haystack); + const options = arguments[arguments.length - 1]; if (typeof needle !== 'string') { diff --git a/package.json b/package.json index f1af7c07..b92e3dde 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bigcommerce/stencil-paper", - "version": "2.0.23", + "version": "2.0.24", "description": "A stencil plugin to register partials and helpers from handlebars and returns the compiled version for the stencil platform.", "main": "index.js", "author": "Bigcommerce", diff --git a/test/helpers/replace.js b/test/helpers/replace.js index 58bcb1ee..68c68bfa 100644 --- a/test/helpers/replace.js +++ b/test/helpers/replace.js @@ -14,6 +14,7 @@ describe('replace helper', function() { const context = { content: "Either you run the %%var%% or the %%var%% runs you", price: '$49.99', + facet: 'brand', }; it('should replace all ocurrance of %%var%% with "day"', function(done) { @@ -45,6 +46,13 @@ describe('replace helper', function() { done(); }); + it('should work nicely with other helpers that use safestring', function(done) { + expect(c("Replace+Concat+Hyphenated: fifth-{{#replace '&' (concat '&' (hyphenate facet)) }}{{/replace}}", context)) + .to.be.equal("Replace+Concat+Hyphenated: fifth-brand"); + + done(); + }); + it('should gracefully handle not strings', function(done) { expect(c("{{#replace something price}}{{/replace}}", context)) .to.be.equal('');