Skip to content

Commit

Permalink
Auto-convert github.com source URLs to use https
Browse files Browse the repository at this point in the history
This avoids having to fix every rockspec that uses github.com.

See https://github.blog/2021-09-01-improving-git-protocol-security-github/

For more context, see:
teal-language/tl#494
  • Loading branch information
hishamhm committed Nov 8, 2021
1 parent 11ddae6 commit 9ff512e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/luarocks/fetch.lua
Expand Up @@ -502,6 +502,14 @@ function fetch.fetch_sources(rockspec, extract, dest_dir)
assert(type(extract) == "boolean")
assert(type(dest_dir) == "string" or not dest_dir)

-- auto-convert git://github.com URLs to use git+https
-- see https://github.blog/2021-09-01-improving-git-protocol-security-github/
if rockspec.source.url:match("^git://github%.com/")
or rockspec.source.url:match("^git://www%.github%.com/") then
rockspec.source.url = rockspec.source.url:gsub("^git://", "git+https://")
rockspec.source.protocol = "git+https"
end

local protocol = rockspec.source.protocol
local ok, proto
if dir.is_basic_protocol(protocol) then
Expand All @@ -522,6 +530,7 @@ function fetch.fetch_sources(rockspec, extract, dest_dir)
return nil, "Can't download "..rockspec.source.url.." -- only downloading from "..cfg.only_sources_from
end
end

return proto.get_sources(rockspec, extract, dest_dir)
end

Expand Down

0 comments on commit 9ff512e

Please sign in to comment.