From 2c41acab4c97f584e8e199b31dc456194b8d7e6c Mon Sep 17 00:00:00 2001 From: tsne Date: Mon, 6 Jul 2026 16:52:20 +0200 Subject: initial --- internal/cli/path_prefix_test.go | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 internal/cli/path_prefix_test.go (limited to 'internal/cli/path_prefix_test.go') diff --git a/internal/cli/path_prefix_test.go b/internal/cli/path_prefix_test.go new file mode 100644 index 0000000..bdb4e42 --- /dev/null +++ b/internal/cli/path_prefix_test.go @@ -0,0 +1,52 @@ +package cli + +import ( + "errors" + "testing" +) + +func TestPathPrefixValueSet(t *testing.T) { + cases := map[string]string{ + "": "", + "/": "", + "foo": "foo", + "/foo": "foo", + "foo/": "foo", + "/foo/": "foo", + "foo//bar": "foo/bar", + "foo/./bar": "foo/bar", + "foo/bar/..": "foo", + "a/b/../c": "a/c", + } + for in, want := range cases { + var p string + v := &pathPrefixValue{p: &p} + if err := v.Set(in); err != nil { + t.Errorf("Set(%q): unexpected error %v", in, err) + continue + } + if p != want { + t.Errorf("Set(%q) = %q, want %q", in, p, want) + } + } +} + +func TestPathPrefixValueSetEscapes(t *testing.T) { + for _, in := range []string{"..", "../x", "/../x", "foo/../../x"} { + var p string + v := &pathPrefixValue{p: &p} + var ue usageError + if err := v.Set(in); !errors.As(err, &ue) { + t.Errorf("Set(%q): expected usageError, got %v", in, err) + } + } +} + +func TestPrefixedPath(t *testing.T) { + if got := prefixedPath("", "assets/x.js"); got != "assets/x.js" { + t.Errorf("empty prefix: got %q", got) + } + if got := prefixedPath("foo", "assets/x.js"); got != "foo/assets/x.js" { + t.Errorf("prefixed: got %q", got) + } +} -- cgit v1.3