Files
wehub-resource-sync f99010fae1
Desktop Artifacts / Desktop Build (Linux) (push) Waiting to run
Desktop Artifacts / Desktop Build (Windows) (push) Waiting to run
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Waiting to run
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Waiting to run
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Waiting to run
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:36 +08:00

61 lines
1.6 KiB
Go

package parser
import (
"database/sql"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSQLiteURIPath(t *testing.T) {
tests := []struct {
name string
in string
want string
}{
{name: "plain", in: "/data/opencode.db", want: "/data/opencode.db"},
{name: "hash", in: "/data/pro#ject/x.db", want: "/data/pro%23ject/x.db"},
{name: "question mark", in: "/data/a?b/x.db", want: "/data/a%3Fb/x.db"},
{name: "percent", in: "/data/100%/x.db", want: "/data/100%25/x.db"},
{
name: "percent sequence stays literal",
in: "/data/a%3Fb/x.db",
want: "/data/a%253Fb/x.db",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, sqliteURIPath(tc.in))
})
}
}
func TestOpenSQLiteWithSpecialCharPath(t *testing.T) {
// '#' would end the URI path (dropping mode=ro into the fragment) and
// '%41' would percent-decode to 'A' if the path were not escaped.
dir := filepath.Join(t.TempDir(), "pro#ject %41")
require.NoError(t, os.MkdirAll(dir, 0o755))
dbPath := filepath.Join(dir, "opencode.db")
writer, err := sql.Open("sqlite3", dbPath)
require.NoError(t, err)
_, err = writer.Exec("CREATE TABLE t (x INTEGER); INSERT INTO t VALUES (1)")
require.NoError(t, err)
require.NoError(t, writer.Close())
db, err := openOpenCodeDB(dbPath)
require.NoError(t, err)
defer db.Close()
var n int
require.NoError(t, db.QueryRow("SELECT count(*) FROM t").Scan(&n))
assert.Equal(t, 1, n)
_, err = db.Exec("INSERT INTO t VALUES (2)")
require.Error(t, err, "mode=ro must survive special characters in the path")
}