Skip to content

Proposal: avoid double quotes around directive arguments #145

Open
@ale14890591

Description

@ale14890591

Considering

func needsQuote(s string) bool {

Assume I want to create the following line in the config: a "b" "c";

The following code produces the result as a '"b"' '"c"';

d := crossplane.Directives{}
d = append(d, &crossplane.Directive{
	Directive: "a",
	Args:      []string{"\"b\"", "\"c\""},
})
crossplane.BuildFiles(
	crossplane.Payload{
		Config: []crossplane.Config{
			{
				File:   "abc",
				Parsed: d,
			},
		},
	},
	"",
	&crossplane.BuildOptions{},
)

The following code produces the result as a b c;

d := crossplane.Directives{}
d = append(d, &crossplane.Directive{
	Directive: "a",
	Args:      []string{"b", "c"},
})
crossplane.BuildFiles(
	crossplane.Payload{
		Config: []crossplane.Config{
			{
				File:   "abc",
				Parsed: d,
			},
		},
	},
	"",
	&crossplane.BuildOptions{},
)

Would it be a good idea to perform something like this in the needsQuote function?

if strings.HasPrefix(s, "\"") && strings.HasSuffix(s, "\"") ||
	strings.HasPrefix(s, "'") && strings.HasSuffix(s, "'") {
	// if the string starts and ends with quotes, it is already quoted
	return false
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions