Skip to content

Commit

Permalink
[BUGFIX] URL-Encode the project name
Browse files Browse the repository at this point in the history
The project name (ENV var GERRIT_PROJECT) is taken to construct
Gerrit API calls. However it was not URL-encoded, which meant that
characters like '/' (example: GERRIT_PROJECT='some/project/name')
were not escaped from the URL, rendering the API URL corrupt in effect.
  • Loading branch information
sheputis committed May 11, 2023
1 parent 3cf24b2 commit 2570b1a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/gergich.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def revision_number

def change_id
if info[:project] && info[:branch]
"#{info[:project]}~#{ERB::Util.url_encode info[:branch]}~#{info[:change_id]}"
"#{ERB::Util.url_encode info[:project]}~#{ERB::Util.url_encode info[:branch]}~#{info[:change_id]}"
else
info[:change_id]
end
Expand Down
6 changes: 3 additions & 3 deletions spec/gergich_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@
end

describe "#change_id" do
it "supports branches with slashes" do
it "supports branches and project names with slashes" do
allow(ENV).to receive(:[]).with("GERRIT_PATCHSET_REVISION").and_return("commit-ish")
allow(ENV).to receive(:[]).with("GERRIT_PROJECT").and_return("spec-project")
allow(ENV).to receive(:[]).with("GERRIT_PROJECT").and_return("namespace/spec-project")
allow(ENV).to receive(:[]).with("GERRIT_BRANCH").and_return("releases/2017.11.17")
allow(ENV).to receive(:[]).with("GERRIT_CHANGE_ID").and_return("dummychangeset")

expect(described_class.new.change_id) # %2F = / and %7E = ~
.to match("spec-project~releases%2F2017.11.17~dummychangeset")
.to match("namespace%2Fspec-project~releases%2F2017.11.17~dummychangeset")
end
end
end
Expand Down

0 comments on commit 2570b1a

Please sign in to comment.