Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/execext/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func escape(s string) string {
s = strings.ReplaceAll(s, "&", `\&`)
s = strings.ReplaceAll(s, "(", `\(`)
s = strings.ReplaceAll(s, ")", `\)`)
s = strings.ReplaceAll(s, "'", `\'`)
return s
}

Expand Down
24 changes: 24 additions & 0 deletions internal/fingerprint/glob_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fingerprint

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func TestGlobHandlesApostropheInPath(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A table driven test, for each of the cases in the code, would be useful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this test is not very useful. It would be better to make an Executor/Task test where you have a list of files including characters which should be escaped, then run the Task, then check the files are handled correctly. You might even find that such a test exists.

Such a test would cover the entire processing chain (in case it gets broken somewhere else too).

t.Parallel()

baseDir := t.TempDir()
dir := filepath.Join(baseDir, "test'd")
require.NoError(t, os.Mkdir(dir, 0o755))

file := filepath.Join(dir, "test.in")
require.NoError(t, os.WriteFile(file, []byte("input"), 0o644))

matches, err := glob(dir, "test.in")
require.NoError(t, err)
require.Equal(t, []string{filepath.ToSlash(file)}, matches)
}