Skip to content

Commit

Permalink
Fix ARGV numeric string handling
Browse files Browse the repository at this point in the history
  • Loading branch information
benhoyt committed Dec 23, 2021
1 parent 3f3dbc0 commit 952d74c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions goawk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ func TestCommandLine(t *testing.T) {
"A=1, B=0\n\tARGV[1] = B=2\n\tARGV[2] = testdata/test.countries\nA=1, B=2\n", ""},
{[]string{`END { print (x==42) }`, "x=42.0"}, "", "1\n", ""},
{[]string{"-v", "x=42.0", `BEGIN { print (x==42) }`}, "", "1\n", ""},
{[]string{`BEGIN { print(ARGV[1]<2, ARGV[2]<2); ARGV[1]="10"; ARGV[2]="10x"; print(ARGV[1]<2, ARGV[2]<2) }`,
"10", "10x"}, "", "0 1\n1 1\n", ""},

// Error handling
{[]string{}, "", "", "usage: goawk [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]"},
Expand Down
2 changes: 1 addition & 1 deletion interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func ExecProgram(program *Program, config *Config) (int, error) {
p.setArrayValue(ScopeGlobal, argvIndex, "0", str(config.Argv0))
p.argc = len(config.Args) + 1
for i, arg := range config.Args {
p.setArrayValue(ScopeGlobal, argvIndex, strconv.Itoa(i+1), str(arg))
p.setArrayValue(ScopeGlobal, argvIndex, strconv.Itoa(i+1), numStr(arg))
}
p.filenameIndex = 1
p.hadFiles = false
Expand Down

0 comments on commit 952d74c

Please sign in to comment.