From b4996dad81ae5699c009b6100650210c8fb65ce2 Mon Sep 17 00:00:00 2001 From: Lisa <101237384+LisaIsCoding@users.noreply.github.com> Date: Wed, 18 Oct 2023 17:16:51 +0800 Subject: [PATCH 01/12] Update dburl.go --- dburl.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dburl.go b/dburl.go index 211dd56..055cbb1 100644 --- a/dburl.go +++ b/dburl.go @@ -11,7 +11,9 @@ package dburl import ( "database/sql" + "fmt" "net/url" + "regexp" "strings" ) @@ -70,11 +72,28 @@ type URL struct { // "scheme://" but "scheme:"), and the database scheme does not support opaque // components, Parse will attempt to re-process the URL as "scheme://". func Parse(urlstr string) (*URL, error) { + // Use regex to find and encode the password + userPassRe := regexp.MustCompile(`^([^:/]*:/{2})([^:]*):([^@]*)@`) + prefixRe := regexp.MustCompile(`^([^:/]*:/{1,2})`) + switch { + case userPassRe.MatchString(urlstr): + urlstr = userPassRe.ReplaceAllStringFunc(urlstr, func(m string) string { + parts := userPassRe.FindStringSubmatch(m) + prefix := parts[1] + return fmt.Sprintf("%s%s:%s@", prefix, parts[2], url.QueryEscape(parts[3])) + }) + case prefixRe.MatchString(urlstr): + // no need to do anything + default: + // for strings like "file:myfile.sqlite3?loc=auto", also no need to do anything + } + // parse url v, err := url.Parse(urlstr) if err != nil { return nil, err } + if v.Scheme == "" { return nil, ErrInvalidDatabaseScheme } From 2f073060e0ef02d146078e938347d344a7ba1f7e Mon Sep 17 00:00:00 2001 From: Lisa <101237384+LisaIsCoding@users.noreply.github.com> Date: Wed, 18 Oct 2023 17:33:43 +0800 Subject: [PATCH 02/12] Update dburl.go decode the password after `url.Parse(urlstr)` --- dburl.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dburl.go b/dburl.go index 055cbb1..3f021af 100644 --- a/dburl.go +++ b/dburl.go @@ -94,6 +94,15 @@ func Parse(urlstr string) (*URL, error) { return nil, err } + // decode the password + if pass, isPwdSet := v.User.Password(); isPwdSet { + passDecode, err := url.QueryUnescape(pass) + if err != nil { + return nil, err + } + v.User = url.UserPassword(v.User.Username(), passDecode) + } + if v.Scheme == "" { return nil, ErrInvalidDatabaseScheme } From 736c3a8c6f68062b80d8a4a3415bf0b78df11213 Mon Sep 17 00:00:00 2001 From: Lisa <101237384+LisaIsCoding@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:53:11 +0800 Subject: [PATCH 03/12] Update go.mod: github.com/LisaIsCoding/dburl --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2eb00d4..b2b209c 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/xo/dburl +github.com/LisaIsCoding/dburl go 1.20 From d63428d440161e4ae79eefc63c941d0ff6574110 Mon Sep 17 00:00:00 2001 From: Lisa <101237384+LisaIsCoding@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:57:58 +0800 Subject: [PATCH 04/12] Update go.mod: recover --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index b2b209c..0683f68 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -github.com/LisaIsCoding/dburl +github.com/xo/dburl go 1.20 From dd9f620df986d5a3bfaa5b2db17fad3b9c5cd3c2 Mon Sep 17 00:00:00 2001 From: Lisa <101237384+LisaIsCoding@users.noreply.github.com> Date: Wed, 18 Oct 2023 19:00:03 +0800 Subject: [PATCH 05/12] Update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0683f68..2eb00d4 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -github.com/xo/dburl +module github.com/xo/dburl go 1.20 From 4485a5d46e3604991b9ad52dc66b2200245c3689 Mon Sep 17 00:00:00 2001 From: Lisa <101237384+LisaIsCoding@users.noreply.github.com> Date: Wed, 18 Oct 2023 22:33:04 +0800 Subject: [PATCH 06/12] Update dburl.go: // Use regex to find and encode the password twice to handle comlicated password like: A7p0@jch5Vj_+-,&=!@$%^*() --- dburl.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/dburl.go b/dburl.go index 3f021af..52c95df 100644 --- a/dburl.go +++ b/dburl.go @@ -12,6 +12,7 @@ package dburl import ( "database/sql" "fmt" + "log" "net/url" "regexp" "strings" @@ -72,15 +73,16 @@ type URL struct { // "scheme://" but "scheme:"), and the database scheme does not support opaque // components, Parse will attempt to re-process the URL as "scheme://". func Parse(urlstr string) (*URL, error) { - // Use regex to find and encode the password - userPassRe := regexp.MustCompile(`^([^:/]*:/{2})([^:]*):([^@]*)@`) + // Use regex to find and encode the password twice to handle comlicated + // password like: A7p0@jch5Vj_+-,&=!@$%^*() + userPassRe := regexp.MustCompile(`^([^:/]*:/{2})([^:]*):(.*)@`) prefixRe := regexp.MustCompile(`^([^:/]*:/{1,2})`) switch { case userPassRe.MatchString(urlstr): urlstr = userPassRe.ReplaceAllStringFunc(urlstr, func(m string) string { parts := userPassRe.FindStringSubmatch(m) prefix := parts[1] - return fmt.Sprintf("%s%s:%s@", prefix, parts[2], url.QueryEscape(parts[3])) + return fmt.Sprintf("%s%s:%s@", prefix, parts[2], url.QueryEscape(url.QueryEscape(parts[3]))) }) case prefixRe.MatchString(urlstr): // no need to do anything @@ -89,17 +91,24 @@ func Parse(urlstr string) (*URL, error) { } // parse url - v, err := url.Parse(urlstr) + var v = &url.URL{} + var err error + v, err = url.Parse(urlstr) if err != nil { return nil, err } - // decode the password + // decode the password twice if pass, isPwdSet := v.User.Password(); isPwdSet { passDecode, err := url.QueryUnescape(pass) if err != nil { return nil, err } + + passDecode, err = url.QueryUnescape(passDecode) + if err != nil { + return nil, err + } v.User = url.UserPassword(v.User.Username(), passDecode) } @@ -167,6 +176,7 @@ func Parse(urlstr string) (*URL, error) { if u.DSN, u.GoDriver, err = scheme.Generator(u); err != nil { return nil, err } + return u, nil } From 584a8a37570d246e921e7e44826c8fe31a9bf433 Mon Sep 17 00:00:00 2001 From: Lisa <101237384+LisaIsCoding@users.noreply.github.com> Date: Wed, 18 Oct 2023 23:21:37 +0800 Subject: [PATCH 07/12] Update dburl.go fix "log" imported and not used --- dburl.go | 1 - 1 file changed, 1 deletion(-) diff --git a/dburl.go b/dburl.go index 52c95df..f125e31 100644 --- a/dburl.go +++ b/dburl.go @@ -12,7 +12,6 @@ package dburl import ( "database/sql" "fmt" - "log" "net/url" "regexp" "strings" From 21afdb0905be0aeec5461da7c59d8a618155be23 Mon Sep 17 00:00:00 2001 From: Lisa <101237384+LisaIsCoding@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:54:41 +0000 Subject: [PATCH 08/12] fix decode pass --- dburl.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/dburl.go b/dburl.go index f125e31..591b539 100644 --- a/dburl.go +++ b/dburl.go @@ -97,17 +97,13 @@ func Parse(urlstr string) (*URL, error) { return nil, err } - // decode the password twice + // decode the password if pass, isPwdSet := v.User.Password(); isPwdSet { passDecode, err := url.QueryUnescape(pass) if err != nil { return nil, err } - passDecode, err = url.QueryUnescape(passDecode) - if err != nil { - return nil, err - } v.User = url.UserPassword(v.User.Username(), passDecode) } From d5abe9bd6a4560359dc41d279cad685afaf22e39 Mon Sep 17 00:00:00 2001 From: Lisa <101237384+LisaIsCoding@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:38:00 +0000 Subject: [PATCH 09/12] add comment inside Parse: // Use regex to find and encode the password twice to handle comlicated // password like: A7p0jch5Vj_+-,&=!@#$%^*(). Since inside the url.Parse will // call unescape(`parse` --> `parseAuthority` --> `unescape`) --- dburl.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dburl.go b/dburl.go index 591b539..6a68317 100644 --- a/dburl.go +++ b/dburl.go @@ -73,7 +73,8 @@ type URL struct { // components, Parse will attempt to re-process the URL as "scheme://". func Parse(urlstr string) (*URL, error) { // Use regex to find and encode the password twice to handle comlicated - // password like: A7p0@jch5Vj_+-,&=!@$%^*() + // password like: A7p0jch5Vj_+-,&=!@#$%^*(). Since inside the url.Parse will + // call unescape(`parse` --> `parseAuthority` --> `unescape`) userPassRe := regexp.MustCompile(`^([^:/]*:/{2})([^:]*):(.*)@`) prefixRe := regexp.MustCompile(`^([^:/]*:/{1,2})`) switch { From 9557d2267e855af817c6454bbfde8b61b95e4b8b Mon Sep 17 00:00:00 2001 From: Lisa <101237384+LisaIsCoding@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:56:21 +0000 Subject: [PATCH 10/12] Parse: vars naming --- dburl.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/dburl.go b/dburl.go index 6a68317..80155fb 100644 --- a/dburl.go +++ b/dburl.go @@ -91,21 +91,19 @@ func Parse(urlstr string) (*URL, error) { } // parse url - var v = &url.URL{} - var err error - v, err = url.Parse(urlstr) + v, err := url.Parse(urlstr) if err != nil { return nil, err } // decode the password - if pass, isPwdSet := v.User.Password(); isPwdSet { - passDecode, err := url.QueryUnescape(pass) + if password, isPasswordSet := v.User.Password(); isPasswordSet { + passwordDecode, err := url.QueryUnescape(password) if err != nil { return nil, err } - v.User = url.UserPassword(v.User.Username(), passDecode) + v.User = url.UserPassword(v.User.Username(), passwordDecode) } if v.Scheme == "" { From 646425904a8dbe441eb1595cc7eda3243864c356 Mon Sep 17 00:00:00 2001 From: "deepsource-io[bot]" <42547082+deepsource-io[bot]@users.noreply.github.com> Date: Fri, 20 Oct 2023 04:13:31 +0000 Subject: [PATCH 11/12] ci: add .deepsource.toml --- .deepsource.toml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .deepsource.toml diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 0000000..3511935 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,7 @@ +version = 1 + +[[analyzers]] +name = "go" + + [analyzers.meta] + import_root = "github.com/LisaIsCoding/dburl" \ No newline at end of file From da9cddd95c454397071f81a2b14bbe25e5b0314e Mon Sep 17 00:00:00 2001 From: "codesee-maps[bot]" <86324825+codesee-maps[bot]@users.noreply.github.com> Date: Mon, 23 Oct 2023 07:01:28 +0000 Subject: [PATCH 12/12] Install the CodeSee workflow. Learn more at https://docs.codesee.io --- .github/workflows/codesee-arch-diagram.yml | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/codesee-arch-diagram.yml diff --git a/.github/workflows/codesee-arch-diagram.yml b/.github/workflows/codesee-arch-diagram.yml new file mode 100644 index 0000000..a72f58b --- /dev/null +++ b/.github/workflows/codesee-arch-diagram.yml @@ -0,0 +1,23 @@ +# This workflow was added by CodeSee. Learn more at https://codesee.io/ +# This is v2.0 of this workflow file +on: + push: + branches: + - master + pull_request_target: + types: [opened, synchronize, reopened] + +name: CodeSee + +permissions: read-all + +jobs: + codesee: + runs-on: ubuntu-latest + continue-on-error: true + name: Analyze the repo with CodeSee + steps: + - uses: Codesee-io/codesee-action@v2 + with: + codesee-token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }} + codesee-url: https://app.codesee.io