Skip to content

fix(textutil): make template placeholder regex non-greedy#614

Open
adityagiri3600 wants to merge 3 commits intostackql:mainfrom
adityagiri3600:main
Open

fix(textutil): make template placeholder regex non-greedy#614
adityagiri3600 wants to merge 3 commits intostackql:mainfrom
adityagiri3600:main

Conversation

@adityagiri3600
Copy link

Description

Fixes placeholder matching in textutil.GetTemplateLikeString by switching from a greedy regex to a non-greedy regex.

GetTemplateLikeString is intended to normalize template placeholders {{...}} so matching can work on the surrounding literal text.

Using a greedy pattern {{.*}} can consume from the first {{ to the last }} when multiple placeholders exist in one string, collapsing distinct placeholders into one match.

Switching to non-greedy {{.*?}} ensures each placeholder is replaced independently, which preserves expected behavior for multi-placeholder inputs.

Example:
Input: prefix {{one}} middle {{two}} suffix
Greedy {{.*}} matches: {{one}} middle {{two}}
Non-greedy {{.*?}} matches: {{one}} and {{two}}

Type of change

  • Bug fix (non-breaking change to fix a bug).
  • Feature (non-breaking change to add functionality).
  • Breaking change.
  • Other (eg: documentation change). Please explain.

Issues referenced.

None

Evidence

Local command run: go test ./pkg/textutil
Result: pass ([no test files], package compiles successfully)

Checklist:

  • A full round of testing has been completed, and there are no test failures as a result of these changes.
  • The changes are covered with functional and/or integration robot testing.
  • The changes work on all supported platforms.
  • Unit tests pass locally, as per the developer guide.
  • Robot tests pass locally, as per the developer guide.
  • Linter passes locally, as per the developer guide.

Variations

This is a one-line, non-breaking regex correction in textutil.go with no interface or behavior changes beyond fixing greedy matching for multi-placeholder strings.
I ran a targeted package test (go test ./pkg/textutil) as lightweight evidence for this minimal change.
I did not run full unit/robot/lint suites for this tiny scoped fix.

Tech Debt

No technical debt introduced by this change set.

@general-kroll-4-life
Copy link
Contributor

general-kroll-4-life commented Feb 10, 2026

@adityagiri3600 cheers for the contribution. Please add a couple of go tests to verify the behaviour is unchanged for simple input and as desired for more complex

@adityagiri3600
Copy link
Author

will do!

@general-kroll-4-life
Copy link
Contributor

@adityagiri3600 good progress. Please amend so that the linter passes now: https://github.com/stackql/stackql/actions/runs/21864103894/job/63119969601

Thanks again

@adityagiri3600
Copy link
Author

@general-kroll-4-life Fixed now, and apologies for missing that in my first pass. Thanks!

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.

3 participants