Skip to content

Commit 6813597

Browse files
committed
update sqlite escaping, add symlink check, remove escaping for sqlite + postgres since they're not using connection urls
1 parent b01deee commit 6813597

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/.idea
22
/.vscode
33
/dev/elasticsearch
4-
DS_Store
4+
DS_Store
5+
.DS_Store
6+
__debug*
7+
*.db

core/src/plugins/gorm/db.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ package gorm_plugin
1818

1919
import (
2020
"fmt"
21+
"net/url"
22+
"strconv"
23+
"time"
24+
2125
"github.com/clidey/whodb/core/src/common"
2226
"github.com/clidey/whodb/core/src/engine"
2327
"github.com/clidey/whodb/core/src/plugins"
2428
"gorm.io/gorm"
25-
"net/url"
26-
"strconv"
27-
"time"
2829
)
2930

3031
const (
@@ -111,11 +112,23 @@ func (p *GormPlugin) ParseConnectionConfig(config *engine.PluginConfig) (*Connec
111112
return nil, err
112113
}
113114

115+
database := config.Credentials.Database
116+
username := config.Credentials.Username
117+
password := config.Credentials.Password
118+
hostname := config.Credentials.Hostname
119+
120+
if p.Type != engine.DatabaseType_Sqlite3 && p.Type != engine.DatabaseType_Postgres {
121+
database = url.PathEscape(database)
122+
username = url.PathEscape(username)
123+
password = url.PathEscape(password)
124+
hostname = url.PathEscape(hostname)
125+
}
126+
114127
input := &ConnectionInput{
115-
Username: url.PathEscape(config.Credentials.Username),
116-
Password: url.PathEscape(config.Credentials.Password),
117-
Database: url.PathEscape(config.Credentials.Database),
118-
Hostname: url.PathEscape(config.Credentials.Hostname),
128+
Username: username,
129+
Password: password,
130+
Database: database,
131+
Hostname: hostname,
119132
Port: port,
120133
ParseTime: parseTime,
121134
Loc: loc,

core/src/plugins/sqlite3/db.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func (p *Sqlite3Plugin) DB(config *engine.PluginConfig) (*gorm.DB, error) {
4545
}
4646
database := connectionInput.Database
4747
fileNameDatabase := filepath.Join(getDefaultDirectory(), database)
48+
fileNameDatabase, err = filepath.EvalSymlinks(fileNameDatabase)
49+
if err != nil {
50+
return nil, err
51+
}
4852
if !strings.HasPrefix(fileNameDatabase, getDefaultDirectory()) {
4953
return nil, errDoesNotExist
5054
}

core/src/plugins/sqlite3/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ func (p *Sqlite3Plugin) GetColTypeQuery() string {
4949

5050
func (p *Sqlite3Plugin) EscapeSpecificIdentifier(identifier string) string {
5151
identifier = strings.Replace(identifier, "\"", "\"\"", -1)
52-
return "\"" + identifier + "\""
52+
return identifier
5353
}

0 commit comments

Comments
 (0)