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(template): unescape escape templates when not doing partial resolution #5680

Merged
merged 6 commits into from
Aug 23, 2024

Conversation

edvald
Copy link
Collaborator

@edvald edvald commented Jan 30, 2024

Fixes: #3989

eysi09
eysi09 previously approved these changes Jan 30, 2024
Copy link
Collaborator

@eysi09 eysi09 left a comment

Choose a reason for hiding this comment

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

LGTM

@TimBeyer
Copy link
Contributor

TimBeyer commented Jan 30, 2024

When I was trying to resolve this I had a few more test cases. Maybe it makes sense to check if those pass too?
I'm not sure they all make sense, for example the resolving strings within escaped strings, but I think the other cases all were causing issues that were somewhere deeper in the parser where it wouldn't recognize escaped things when embedded in a larger string.

  it("should allow nesting normal strings within escaped strings", () => {
    const res = resolveTemplateString("$${var.${foo}}", new TestContext({ foo: "yes" }), { unescape: true })
    expect(res).to.equal("${var.yes}")
  })

  it("should allow nesting escaped strings within normal strings", () => {
    const res = resolveTemplateString("${foo == 'yes' ? '$${bar}' : 'fail' }", new TestContext({ foo: "yes" }), { unescape: true })
    expect(res).to.equal("${bar}")
  })


  it.only("should escape things correctly", () => {
    const res = resolveTemplateString("$${env.TEST_ENV}", new TestContext({}), {
      unescape: true,
    })
    expect(res).to.equal("${env.TEST_ENV}")
  })

  it.only("should escape things correctly", () => {
    const res = resolveTemplateString("foo $${env.TEST_ENV} bar", new TestContext({}), {
      unescape: true,
    })
    expect(res).to.equal("foo ${env.TEST_ENV} bar")
  })

  it.only("should escape things correctly", () => {
    const res = resolveTemplateString("$${env:TEST_ENV}", new TestContext({}), {
      unescape: true,
    })
    expect(res).to.equal("${env:TEST_ENV}")
  })


  it.only("should escape things correctly", () => {
    const res = resolveTemplateString("foo $${env:TEST_ENV} bar", new TestContext({}), {
      unescape: true,
    })
    expect(res).to.equal("foo ${env:TEST_ENV} bar")
  })

  it("should escape things correctly", () => {
    const res = resolveTemplateString("${foo}-$${env:TEST_ENV}", new TestContext({ foo: "foo" }), {
      unescape: true,
    })
    expect(res).to.equal("foo-${env:TEST_ENV}")
  })

@eysi09
Copy link
Collaborator

eysi09 commented Jan 30, 2024

@TimBeyer, yeah good catch.

Also, the framework tests appear to be failing.

const res = resolveTemplateString({
string: "$${bar}",
context: new TestContext({}),
contextOpts: { allowPartial: true },
Copy link
Member

Choose a reason for hiding this comment

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

It's not really obvious to me how this fixes the end user issue – can we also add an integration test that shows how this fixes the issue in a less synthetic scenario?

@edvald edvald changed the title fix(template): unescape escape templates when not doing partial resolution [WIP] fix(template): unescape escape templates when not doing partial resolution Jan 31, 2024
@edvald
Copy link
Collaborator Author

edvald commented Jan 31, 2024

All fair points, flagging as WIP for now.

Btw the microk8s test failures seem unrelated. Not sure if we've been seeing those as flaky?

@edvald edvald dismissed eysi09’s stale review February 1, 2024 15:49

Need to update the PR

@edvald
Copy link
Collaborator Author

edvald commented Feb 1, 2024

@TimBeyer this isn't the current behavior, so it would be a breaking change:

it("should allow nesting normal strings within escaped strings", () => {
const res = resolveTemplateString("$${var.${foo}}", new TestContext({ foo: "yes" }), { unescape: true })
expect(res).to.equal("${var.yes}")
})

@vvagaytsev vvagaytsev marked this pull request as draft August 22, 2024 14:14
Excluded one test case that assumed breaking chnahes in the behaviour.

Co-authored-by: Tim Beyer <[email protected]>
For symmetric testing of mac/linux and win env var reference format.
Deduplicate code with parameterized tests.
FIXME: Windows-style env vars references still don't work.
Here we need to distinguish `undefined` and `false`.
@vvagaytsev vvagaytsev requested review from eysi09 and twelvemo August 23, 2024 10:21
@vvagaytsev vvagaytsev marked this pull request as ready for review August 23, 2024 10:21
@vvagaytsev vvagaytsev changed the title [WIP] fix(template): unescape escape templates when not doing partial resolution fix(template): unescape escape templates when not doing partial resolution Aug 23, 2024
@eysi09 eysi09 added this pull request to the merge queue Aug 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 23, 2024
@vvagaytsev vvagaytsev added this pull request to the merge queue Aug 23, 2024
Merged via the queue into main with commit cc6e41c Aug 23, 2024
40 checks passed
@vvagaytsev vvagaytsev deleted the fix-unescape branch August 23, 2024 13:12
vvagaytsev added a commit that referenced this pull request Aug 28, 2024
Patches commit 8df3a4f from #5680.
Module variables are resolved in a standalone function `resolveVariables`.
That function should also skip un-escaping.
github-merge-queue bot pushed a commit that referenced this pull request Aug 28, 2024
…configs (#6408)

* fix(template): skip un-escaping while module vars resolution

Patches commit 8df3a4f from #5680.
Module variables are resolved in a standalone function `resolveVariables`.
That function should also skip un-escaping.

* fix(template): fix function definition

Use its own argument instead of a closure.

* refactor(template): pull function `shouldUnescape` up

* fix(template): fix too greedy pattern for escaped string
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.

Escaping template strings not working
5 participants