Skip to content

Commit

Permalink
Allow replace helper to accept safestrings, release 2.0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
bookernath committed Jun 5, 2020
1 parent 8790a28 commit 9609665
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions helpers/replace.js
Original file line number Diff line number Diff line change
@@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 8 additions & 0 deletions test/helpers/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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('');
Expand Down

0 comments on commit 9609665

Please sign in to comment.