File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -474,8 +474,11 @@ def build_golang_download_url(purl):
474474 if namespace :
475475 name = f"{ namespace } /{ name } "
476476
477+ ename = escape_path (name )
478+ eversion = escape_path (version )
479+
477480 if name and version :
478- return f"https://proxy.golang.org/{ name } /@v/{ version } .zip"
481+ return f"https://proxy.golang.org/{ ename } /@v/{ eversion } .zip"
479482
480483
481484@download_router .route ("pkg:pub/.*" )
@@ -536,3 +539,24 @@ def get_repo_download_url(purl):
536539 return get_repo_download_url_by_package_type (
537540 type = type , namespace = namespace , name = name , version = version
538541 )
542+
543+
544+ # TODO: https://github.com/package-url/packageurl-python/issues/196
545+ def escape_path (path : str ) -> str :
546+ """
547+ Return an case-encoded module path or version name.
548+
549+ This is done by replacing every uppercase letter with an exclamation mark followed by the
550+ corresponding lower-case letter, in order to avoid ambiguity when serving from case-insensitive
551+ file systems.
552+
553+ See https://golang.org/ref/mod#goproxy-protocol.
554+ """
555+ escaped_path = ""
556+ for c in path :
557+ if c >= "A" and c <= "Z" :
558+ # replace uppercase with !lowercase
559+ escaped_path += "!" + chr (ord (c ) + ord ("a" ) - ord ("A" ))
560+ else :
561+ escaped_path += c
562+ return escaped_path
Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ def test_purl2url_get_download_url():
101101 "pkg:hex/plug@1.11.1" : "https://repo.hex.pm/tarballs/plug-1.11.1.tar" ,
102102 "pkg:golang/xorm.io/xorm@v0.8.2" : "https://proxy.golang.org/xorm.io/xorm/@v/v0.8.2.zip" ,
103103 "pkg:golang/gopkg.in/ldap.v3@v3.1.0" : "https://proxy.golang.org/gopkg.in/ldap.v3/@v/v3.1.0.zip" ,
104+ "pkg:golang/example.com/M.v3@v3.1.0" : "https://proxy.golang.org/example.com/!m.v3/@v/v3.1.0.zip" ,
104105 "pkg:pub/http@0.13.3" : "https://pub.dev/api/archives/http-0.13.3.tar.gz" ,
105106 "pkg:swift/github.com/Alamofire/Alamofire@5.4.3" : "https://github.com/Alamofire/Alamofire/archive/5.4.3.zip" ,
106107 "pkg:swift/github.com/RxSwiftCommunity/RxFlow@2.12.4" : "https://github.com/RxSwiftCommunity/RxFlow/archive/2.12.4.zip" ,
You can’t perform that action at this time.
0 commit comments