From f15e015d6a916604914b00940127de195f3fe15f Mon Sep 17 00:00:00 2001 From: mstxq17 <154380808@qq.com> Date: Mon, 2 Sep 2024 13:38:37 +0800 Subject: [PATCH] fix: fix bug of schema:host new feature --- .github/workflows/release.yml | 2 +- core/extract/simple_url.go | 14 ++++++++++---- gr_test.sh | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 707d48b..849d042 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: # either 'goreleaser' (default) or 'goreleaser-pro' distribution: goreleaser version: latest - args: release --rm-dist + args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Your GoReleaser Pro key, if you are using the 'gorel \ No newline at end of file diff --git a/core/extract/simple_url.go b/core/extract/simple_url.go index 70a27d1..d275968 100644 --- a/core/extract/simple_url.go +++ b/core/extract/simple_url.go @@ -3,24 +3,30 @@ package extract import ( "fmt" "net/url" + "strings" ) func SimpleUrl(input string) (string, bool, error) { + var hasSchema bool + if strings.Contains(input, "://") { + hasSchema = true + } else { + hasSchema = false + input = fmt.Sprintf("http://%s", input) + } parsed, err := url.Parse(input) if err != nil { return "", false, err } - if parsed.Scheme != "" { + if hasSchema == true { tSimpleUrl := fmt.Sprintf("%s://%s", parsed.Scheme, parsed.Host) return tSimpleUrl, true, nil } else { // 拼接协议进行解析 - modifiedHost := fmt.Sprintf("http://%s", input) - parsed, err := url.Parse(modifiedHost) if err != nil { return "", false, err } else { - tSimpleUrl := fmt.Sprintf("%s", parsed.Hostname()) + tSimpleUrl := fmt.Sprintf("%s", parsed.Host) return tSimpleUrl, false, nil } } diff --git a/gr_test.sh b/gr_test.sh index 0617c3f..8512171 100755 --- a/gr_test.sh +++ b/gr_test.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -goreleaser --skip-publish --snapshot --rm-dist \ No newline at end of file +goreleaser --skip "publish" --snapshot --clean \ No newline at end of file