Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url_encode throws on undefined value #479

Closed
pdehaan opened this issue Feb 21, 2022 · 2 comments
Closed

url_encode throws on undefined value #479

pdehaan opened this issue Feb 21, 2022 · 2 comments
Labels

Comments

@pdehaan
Copy link
Contributor

pdehaan commented Feb 21, 2022

Probably an edge case, but somebody encountered this while migrating their blog from Jekyll to Eleventy (ref: 11ty/eleventy#2234 (comment)) and thought I'd verify if there is some option we're possibly not setting.

const {Liquid} = require("liquidjs");

const engine = new Liquid({
  strictVariables: false
});
const tpl = engine.parse('{{ v | url_encode }}');
engine.render(tpl, {v: undefined}).then(console.log);

// Error: Cannot read properties of undefined (reading 'split'), line:1, col:1

So basically this is calling {{ undefined | url_encode }} and throwing the following error:

"Error: Cannot read properties of undefined (reading 'split')"

(Although the error changes slightly depending on which filter you are calling.)

I'm not convinced whether or not this is something that is Liquid's responsibility (throwing errors when a filter tries to do something w/ a null or undefined value when it expects a string/whatever). I could easily be convinced either way, but just wanted to run it past you in case I'm missing some semi-obvious setting in the LiquidOptions class.

@harttle
Copy link
Owner

harttle commented Feb 21, 2022

Regarding undefined variables, it's a bit confusing that errors are coming from two procedures

  1. reading scope property. Whether or not throw depends on strictVariables
  2. Executing filters and tags using these undefined variables. It's filter specific and Shopify liquid also have this behavior regardless strictVariables.

I guess what we can do is to align with the ruby version. If one filter in ruby tolerates undefined variable, liquidjs should also do the same.

@harttle harttle changed the title Cannot read properties of undefined (reading 'split') when calling filter w/ undefined value url_encode throws on undefined value Feb 23, 2022
github-actions bot pushed a commit that referenced this issue Feb 23, 2022
# [9.35.0](v9.34.1...v9.35.0) (2022-02-23)

### Bug Fixes

* `url_encode` throws on undefined value, fixes [#479](#479) ([ca3240c](ca3240c))

### Features

* expose all tags/filters and TimezoneDate, closes [#464](#464) ([dab8a29](dab8a29))
@github-actions
Copy link

🎉 This issue has been resolved in version 9.35.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants