67
67
//gpinOldRegex = regexp.MustCompile(`^(?P<root>gopkg\.in/(?:([a-z0-9][-a-z0-9]+)/)?((?:v0|v[1-9][0-9]*)(?:\.0|\.[1-9][0-9]*){0,2}(-unstable)?)/([a-zA-Z][-a-zA-Z0-9]*)(?:\.git)?)((?:/[a-zA-Z][-a-zA-Z0-9]*)*)$`)
68
68
bbRegex = regexp .MustCompile (`^(?P<root>bitbucket\.org(?P<bitname>/[A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+))((?:/[A-Za-z0-9_.\-]+)*)$` )
69
69
//lpRegex = regexp.MustCompile(`^(?P<root>launchpad\.net/([A-Za-z0-9-._]+)(/[A-Za-z0-9-._]+)?)(/.+)?`)
70
- lpRegex = regexp .MustCompile (`^(?P<root>launchpad\.net(/[A-Za-z0-9-._]+))((?:/[A-Za-z0-9_.\-]+)*)?` )
70
+ lpRegex = regexp .MustCompile (`^(?P<root>launchpad\.net(/[A-Za-z0-9-._]+))((?:/[A-Za-z0-9_.\-]+)*)?$ ` )
71
71
//glpRegex = regexp.MustCompile(`^(?P<root>git\.launchpad\.net/([A-Za-z0-9_.\-]+)|~[A-Za-z0-9_.\-]+/(\+git|[A-Za-z0-9_.\-]+)/[A-Za-z0-9_.\-]+)$`)
72
72
glpRegex = regexp .MustCompile (`^(?P<root>git\.launchpad\.net(/[A-Za-z0-9_.\-]+))((?:/[A-Za-z0-9_.\-]+)*)$` )
73
73
//gcRegex = regexp.MustCompile(`^(?P<root>code\.google\.com/[pr]/(?P<project>[a-z0-9\-]+)(\.(?P<subrepo>[a-z0-9\-]+))?)(/[A-Za-z0-9_.\-]+)*$`)
@@ -786,7 +786,12 @@ func (hmd *httpMetadataDeducer) deduce(ctx context.Context, path string) (pathDe
786
786
return hmd .deduced , hmd .deduceErr
787
787
}
788
788
789
- func normalizeURI (p string ) (u * url.URL , newpath string , err error ) {
789
+ // normalizeURI takes a path string - which can be a plain import path, or a
790
+ // proper URI, or something SCP-shaped - performs basic validity checks, and
791
+ // returns both a full URL and just the path portion.
792
+ func normalizeURI (p string ) (* url.URL , string , error ) {
793
+ var u * url.URL
794
+ var newpath string
790
795
if m := scpSyntaxRe .FindStringSubmatch (p ); m != nil {
791
796
// Match SCP-like syntax and convert it to a URL.
792
797
// Eg, "[email protected] :user/repo" becomes
@@ -800,6 +805,7 @@ func normalizeURI(p string) (u *url.URL, newpath string, err error) {
800
805
//RawPath: m[3],
801
806
}
802
807
} else {
808
+ var err error
803
809
u , err = url .Parse (p )
804
810
if err != nil {
805
811
return nil , "" , errors .Errorf ("%q is not a valid URI" , p )
@@ -814,11 +820,7 @@ func normalizeURI(p string) (u *url.URL, newpath string, err error) {
814
820
newpath = path .Join (u .Host , u .Path )
815
821
}
816
822
817
- if ! pathvld .MatchString (newpath ) {
818
- return nil , "" , errors .Errorf ("%q is not a valid import path" , newpath )
819
- }
820
-
821
- return
823
+ return u , newpath , nil
822
824
}
823
825
824
826
// fetchMetadata fetches the remote metadata for path.
0 commit comments