Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ganboonhong
Copy link
Contributor

Fix #499

Since URL will be encoded using percent-encoding in

purl, err := nurl.Parse(url)

url like /path/to database/ (it contains whitespace) will be encoded to /path/to%20database/, which causes

if err := instance.Ping(); err != nil {

to return an error.

Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

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

Thanks for the PR and tests!

return nil, err
}
dbfile := strings.Replace(migrate.FilterCustomQuery(purl).String(), "sqlite3://", "", 1)
dbfile, err = nurl.QueryUnescape(dbfile)
Copy link
Member

Choose a reason for hiding this comment

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

The whole connection string cannot be unescaped as the options need to be escaped.
I think we'll need to reconstruct the connection string w/ the host & path unescaped unless you can think of a cleaner way...

Example of what the parsed connection string looks like

Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

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

Oh nice find with the file: prefix!

I agree with you and think there's still value in testing opening paths with spaces in them.

@ganboonhong
Copy link
Contributor Author

Thanks for the suggestion! Already modified the code.

@ganboonhong ganboonhong changed the title sqlite3: Fix error when path to database contains whitespace sqlite3: Add test case with database path contains whitespace Jan 29, 2021
@dhui dhui merged commit eb62a38 into golang-migrate:master Jan 29, 2021
@ganboonhong ganboonhong deleted the sqlite-whitespace branch January 29, 2021 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sqlite3: Unable to open database file if directory contains whitespace
2 participants