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

fix(lib): correct the concat method in TokenizedStringFragments #3772

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

suojae
Copy link

@suojae suojae commented Nov 17, 2024

The concat method was not properly updating this.fragments because Array.prototype.concat returns a new array and does not modify the original array in place. Changed the implementation to use this.fragments.push(...other.fragments); to correctly merge the fragments into this.fragments.

Description

I thought concat method in TokenizedStringFragments was intended to merge fragments from another instance into this.fragments. However, it was not functioning correctly because Array.prototype.concat returns a new array and does not modify the original array in place.

To fix this issue, I updated the concat method to use this.fragments.push(...other.fragments);. This modifies this.fragments in place and ensures that all fragments are correctly merged.

Checklist

  • I have updated the PR title to match CDKTF's style guide
  • I have run the linter on my code locally
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation if applicable
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works if applicable
  • New and existing unit tests pass locally with my changes

The concat method was not properly updating `this.fragments` because `Array.prototype.concat` does not modify the original array in place. Changed the implementation to use `push` with the spread operator to correctly merge fragments.
Copy link

hashicorp-cla-app bot commented Nov 17, 2024

CLA assistant check
All committers have signed the CLA.

@DanielMSchmidt
Copy link
Contributor

Hey, thanks for your help! Could you add a test case that shows which user-facing issue this fix solved so that we don't reintroduce the problem by accident in the future?

@suojae
Copy link
Author

suojae commented Nov 25, 2024

Hi, thank you for your feedback! I have written a test case for the concat method to verify the user-facing issue is resolved. Could you confirm where exactly I should add the test code? I assume it should go into packages/cdktf/test/tokens/string-fragments.test.ts, but please let me know if there's a more appropriate location.

Added a test case to verify that the `concat` method correctly merges fragments from another instance.
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.

2 participants