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

[WIP] fix(template): unescape escape templates when not doing partial resolution #5680

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edvald
Copy link
Collaborator

@edvald edvald commented Jan 30, 2024

No description provided.

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}")
})

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.

None yet

4 participants