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

Incorrect resolve on key on #11

Open
lonegunmanb opened this issue Nov 15, 2023 · 0 comments
Open

Incorrect resolve on key on #11

lonegunmanb opened this issue Nov 15, 2023 · 0 comments

Comments

@lonegunmanb
Copy link

I've tried to decode github action yaml file:

name: build

on:
  push:
    branches:
      - main
  pull_request:
func TestFunction_YamlDecode(t *testing.T) {
	code := `yamldecode("name: build\n\non:\n  push:\n    branches:\n        - main\n    pull_request:\n")`
	exp, diag := hclsyntax.ParseExpression([]byte(code), "test.hcl", hcl.InitialPos)
	require.False(t, diag.HasErrors())
	value, diag := exp.Value(&hcl.EvalContext{Functions: Functions(".")})
	require.False(t, diag.HasErrors())
	valueMap := value.AsValueMap()
	assert.Contains(t, valueMap, "on")
}

The key on has been resolved as true.

I found this issue was caused by the following function in resolve.go:

func (c *Converter) resolveScalar(tag string, src string, style yaml_scalar_style_t) (cty.Value, error) {
	if !resolvableTag(tag) {
		return cty.NilVal, fmt.Errorf("unsupported tag %q", tag)
	}

	// Any data is accepted as a !!str or !!binary.
	// Otherwise, the prefix is enough of a hint about what it might be.
	hint := byte('N')
	if src != "" {
		hint = resolveTable[src[0]]
	}
	if hint != 0 && tag != yaml_STR_TAG && tag != yaml_BINARY_TAG {
		if style == yaml_SINGLE_QUOTED_SCALAR_STYLE || style == yaml_DOUBLE_QUOTED_SCALAR_STYLE {
			return cty.StringVal(src), nil
		}

		// Handle things we can lookup in a map.
>		if item, ok := resolveMap[src]; ok {
			return item.value, nil
		}

I understand that we use this resolveMap to convert on or On to true, but I don't think we should convert yaml keys.

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

No branches or pull requests

1 participant