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

sort filter modifies original array #475

Closed
pdehaan opened this issue Feb 19, 2022 · 0 comments
Closed

sort filter modifies original array #475

pdehaan opened this issue Feb 19, 2022 · 0 comments
Labels

Comments

@pdehaan
Copy link
Contributor

pdehaan commented Feb 19, 2022

Noticed this in Eleventy v1.0.0 (w/ liquidjs@9.34.0).

If I have an array, and I sort it using the sort filter, it seems to modify my original array.
I think I may have expected the sorted array to be a copy of my original and not modifying the reference to the array. I can work around it, but thought maybe worth filing (although i'm sure changing the default behavior may have other backwards compatibility issues).

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

const engine = new Liquid();
const tpl = engine.parse('{{ arr | sort }}');

const arr = ["one", "two", "three", "four", "five"];

engine.render(tpl, {arr}).then(console.log); // ["five", "four", "one", "three", "two"]
console.log(arr); // Actual: "five,four,one,three,two"
                  // Expected: "one,two,three,four,five"
@harttle harttle added the bug label Feb 19, 2022
github-actions bot pushed a commit that referenced this issue Feb 20, 2022
## [9.34.1](v9.34.0...v9.34.1) (2022-02-20)

### Bug Fixes

* array output now join with "" instead of "," ([ab5e245](ab5e245))
* sort filter unexpectedly modifies original array, [#475](#475) ([dbc0497](dbc0497))
@harttle harttle closed this as completed Feb 23, 2022
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