Skip to content

Fix regression when using empty/nil properties with array filters#1944

Merged
ianks merged 6 commits intomainfrom
ianks-fix-backward-breaking
Apr 4, 2025
Merged

Fix regression when using empty/nil properties with array filters#1944
ianks merged 6 commits intomainfrom
ianks-fix-backward-breaking

Conversation

@ianks
Copy link
Copy Markdown
Contributor

@ianks ianks commented Apr 3, 2025

Fixed a regression where empty properties like {{ array | where: '' }} would return an empty array. Now both empty strings and nil properties act as no-ops, simply returning the original array. This makes the library more forgiving when properties are missing or blank, reducing unexpected errors in your templates.

@ianks ianks requested a review from Copilot April 3, 2025 19:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a regression with array filters ensuring that empty strings and nil properties act as no-ops rather than producing errors. Key changes include:

  • Updated tests for the map and where filters to verify that nil and empty string properties return the original array unchanged.
  • Adjusted the map filter and the internal filter_array helper in the standard filters to handle empty properties as no-ops.
  • Bumped the library version from 5.8.2 to 5.8.3.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/integration/standard_filter_test.rb Updated tests to assert no-op behavior when array filters are given nil/empty property values.
lib/liquid/version.rb Updated version to reflect the patch release.
lib/liquid/standardfilters.rb Modified map filter to immediately return the input for an empty property, and adjusted filter_array to remove an early return for empty properties.
Comments suppressed due to low confidence (2)

lib/liquid/standardfilters.rb:995

  • Ensure that the removal of the early return for empty properties in filter_array is intentional; consider adding an inline comment to clarify that an empty property is now handled as a no-op to align with the updated behavior in other filters.
property = Utils.to_s(property)

test/integration/standard_filter_test.rb:588

  • Consider adding test cases for the sum filter (which uses filter_array) with nil or empty properties to ensure consistent no-op behavior across all array filters.
assert_equal(input.flatten, result)

@ianks
Copy link
Copy Markdown
Contributor Author

ianks commented Apr 4, 2025

Verified this against shadowed traffic and things look fine, this should be good to go

@ianks ianks requested review from Maaarcocr, dpetrick and gmalette April 4, 2025 13:55
@ianks ianks force-pushed the ianks-fix-backward-breaking branch from d35f47d to 19e287d Compare April 4, 2025 13:59
@ianks ianks merged commit 2b75bfa into main Apr 4, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants