fix: allow replace() and replaceAll() helpers to handle array inputs#1237
Closed
bhuxhorn wants to merge 4 commits into
Closed
fix: allow replace() and replaceAll() helpers to handle array inputs#1237bhuxhorn wants to merge 4 commits into
bhuxhorn wants to merge 4 commits into
Conversation
…resource logic; update tests. this fixes: adobe#1236
…resource logic; update tests. This fixes: adobe#1236
… into bugfix/1236-fix-indexer-replace
Contributor
|
thanks @bhuxhorn , please sign the Adobe CLA. |
Contributor
|
thanks. I want to wait for @dominique-pfister 's review. |
Comment on lines
+129
to
+133
| if (Array.isArray(s)) { | ||
| return s.map((item) => ( | ||
| item != null ? String(item).replace(searchValue, replaceValue) : item | ||
| )); | ||
| } |
Contributor
There was a problem hiding this comment.
looks good to me as well, just one thing: should we rather filter items that are null (or undefined) instead of returning them in the array?
Contributor
Author
There was a problem hiding this comment.
Done - nulls are now filtered out before mapping; updated the test expectations accordingly.
Contributor
There was a problem hiding this comment.
Thanks, and using the loose un-equality, this will filter out both null and undefined array values, which is fine for me.
…test expectations. adobe#1236
dominique-pfister
approved these changes
Jul 1, 2026
Contributor
|
fixed with. #1240 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
What the changes intend
This PR fixes a
TypeError: s.replace is not a functioncrash that occurs when thereplace()orreplaceAll()value expression helpers inhelix-query.yamlreceive an array as their first argument (such as the output from theattribute()helper).While other indexer helpers like
match,words, andcharactersinherently handle array inputs,replaceandreplaceAllpreviously expected a strict string. This change aligns their behavior with the rest of the helpers and ensures the documented example for combiningreplace()andattribute()works as expected.How they change the existing code
replaceandreplaceAllhelper functions to detect if the incoming value is an array.If (and what) they break
Related Issue
Fixes #1236