-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle quotes in --tla-str and --ext-str in "tk eval" (#1237)
* fix: Handle quotes in --tla-str and --ext-str in "tk eval". Problem: If a string with a quote was passes to tk eval's --tla-str or --ext-str, things would break in an unexpected fashion. Fix: Properly JSON-quote any given string. * test: Add test for the --tla-* and --ext-* flags parsing.
- Loading branch information
1 parent
d712789
commit 7cba21d
Showing
2 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/pflag" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCliCodeParser(t *testing.T) { | ||
fs := pflag.NewFlagSet("test-cli-code-parser", pflag.ContinueOnError) | ||
parseExt, parseTLA := cliCodeParser(fs) | ||
err := fs.Parse([]string{ | ||
"--ext-str", "es=1a \" \U0001f605 ' b\nc\u010f", | ||
"--tla-str", "ts=2a \" \U0001f605 ' b\nc\u010f", | ||
"--ext-code", "ec=1+2", | ||
"--tla-code", "tc=2+3", | ||
"-A", "ts2=ts2", // tla-str | ||
"-V", "es2=es2", // ext-str | ||
}) | ||
assert.NoError(t, err) | ||
ext := parseExt() | ||
assert.Equal(t, map[string]string{ | ||
"es": `"1a \" ` + "\U0001f605" + ` ' b\nc` + "\u010f" + `"`, | ||
"ec": "1+2", | ||
"es2": `"es2"`, | ||
}, ext) | ||
tla := parseTLA() | ||
assert.Equal(t, map[string]string{ | ||
"ts": `"2a \" ` + "\U0001f605" + ` ' b\nc` + "\u010f" + `"`, | ||
"tc": "2+3", | ||
"ts2": `"ts2"`, | ||
}, tla) | ||
} |