geofffranks / spruce

A BOSH template merge tool
MIT License
433 stars 78 forks source link

Force string variable in form of a number in scientific notation to remain string #381

Open MichalChromcak opened 3 months ago

MichalChromcak commented 3 months ago

Issue

Hello,

Today I bumped into an interesting issue - having a variable (commit hash), that is in form of number in scientific notation (2445e120) being interpreted by spruce as a number instead of keeping is as a string.

I could not find a way how to force spruce to keep it as string.

Can you guide me on what is the best way to achieve the expected output?

Fix trials

Using grab

Content of test.yaml

image:
  tag: (( grab $CI_COMMIT_SHORT_SHA ))

Command

export CI_COMMIT_SHORT_SHA=2445e120
spruce merge test.yaml

Output

image:
  tag: .inf

Expected Output

image:
  tag: 2445e120

Using concat

Content of test.yaml

image:
  tag: (( concat "" $CI_COMMIT_SHORT_SHA ))

Command

export CI_COMMIT_SHORT_SHA=2445e120
spruce merge test.yaml

Output

image:
  tag: "2.445e+123"

Expected Output

image:
  tag: 2445e120

Context

Spruce version: v1.31.0

geofffranks commented 3 months ago

Looks like this was previously reported in https://github.com/geofffranks/spruce/issues/266, but has no fix. Feel free to PR a solution though!