bigcommerce / paper-handlebars

Paper plugin for rendering via Handlebars.js
BSD 4-Clause "Original" or "Old" License
12 stars 36 forks source link

fix: STRF-10494 last and first helpers works with strings #254

Closed rafa-avila-bc closed 1 year ago

rafa-avila-bc commented 1 year ago

What? Why?

while testing in int i found that the following error is thrown

FailedPrecondition: arr.join is not a function : TypeError: arr.join is not a function
    at stringAlt (/opt/app/node_modules/@bigcommerce/stencil-paper-handlebars/helpers/3p/array.js:312:16)

with the following template:

<div style="background-color:aquamarine;">
    <p style="text-align: center;">
        {{first [1,2,3]}}
    </p>
    <p style="text-align: center;">
        {{first [9,8,7,6,5,4,3,2,1] 3}}
    </p>
    <p style="text-align: center;">
        {{first [1,2,3,4,5,6,7,8,9,0] 15}}
    </p>
    <p style="text-align: center;">
        {{last [1,2,3]}}
    </p>
    <p style="text-align: center;">
        {{last [9,8,7,6,5,4,3,2,1] 8}}
    </p>
    <p style="text-align: center;">
        {{last [1,2,3,4,5,6,7,8,9,0] 15}}
    </p>
</div>

    <div style="background-color: aqua;">
        <p style="text-align: center;">
            {{first "BigCommerce"}}
        </p>
        <p style="text-align: center;">
            {{first "BigCommerce" 3}}
        </p>
        <p style="text-align: center;">
            {{first "BigCommerce" 15}}
        </p>
        <p style="text-align: center;">
            {{last "BigCommerce"}}
        </p>
        <p style="text-align: center;">
            {{last "BigCommerce" 8}}
        </p>
        <p style="text-align: center;">
            {{last "BigCommerce" 15}}
        </p>
    </div>

so I'm adding a guard code here.

How was it tested?

unit test


cc @bigcommerce/storefront-team

zvuki commented 1 year ago

@rafa-avila-bc do you want to update a unit test?

jordanarldt commented 1 year ago

Looks good to me, @rafa-avila-bc make sure to address Andrei's comment before merging 👍

rafa-avila-bc commented 1 year ago

@zvuki I've added unit tests.

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 5.7.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: