Skip to content

Commit b264a35

Browse files
author
Paulo Gomes
committed
libgit2: refactor max length values into constants
Signed-off-by: Paulo Gomes <[email protected]>
1 parent 3ab95a4 commit b264a35

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

pkg/git/libgit2/managed/const.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright 2022 The Flux authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package managed
18+
19+
const (
20+
// URLMaxLength represents the max length for the entire URL
21+
// when cloning Git repositories via HTTP(S).
22+
URLMaxLength = 2048
23+
24+
// PathMaxLength represents the max length for the path element
25+
// when cloning Git repositories via SSH.
26+
PathMaxLength = 4096
27+
)

pkg/git/libgit2/managed/http.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ func createClientRequest(targetUrl string, action git2go.SmartServiceAction, t *
171171
}
172172
}
173173

174-
if len(finalUrl) > 2048 {
175-
return nil, nil, fmt.Errorf("URL exceeds the max length (2048)")
174+
if len(finalUrl) > URLMaxLength {
175+
return nil, nil, fmt.Errorf("URL exceeds the max length (%d)", URLMaxLength)
176176
}
177177

178178
client := &http.Client{

pkg/git/libgit2/managed/ssh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ func (t *sshSmartSubtransport) Action(urlString string, action git2go.SmartServi
130130
return nil, err
131131
}
132132

133-
if len(u.Path) > 4096 {
134-
return nil, fmt.Errorf("path exceeds the max length (4096)")
133+
if len(u.Path) > PathMaxLength {
134+
return nil, fmt.Errorf("path exceeds the max length (%d)", PathMaxLength)
135135
}
136136

137137
// decode URI's path

0 commit comments

Comments
 (0)