v2.30.1 1983e1b

env.go RawHistoryFolder

1package domain
2
3import (
4	"bufio"
5	"bytes"
6	"regexp"
7	"strings"
8)
9
10var envKeyRegex = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)
11var containerNameRegex = regexp.MustCompile(`^[A-Za-z][A-Za-z0-9_-]*$`)
12
13// SanitizeDomainForEnvFile validates and sanitizes a domain name for env file storage.
14// Returns the collision-resistant storage key used for filenames.
15func SanitizeDomainForEnvFile(domainName string) (string, error) {
16	safeDomain, err := NewEnvStorageKey(domainName)
17	if err != nil {
18		return "", err
19	}
20
21	return string(safeDomain), nil
22}
23
24// ParseEnvData parses env data into a key-value map.
25func ParseEnvData(data []byte) (map[string]string, error) {
26	secrets := make(map[string]string)
27	scanner := bufio.NewScanner(bytes.NewReader(data))
28	// Allow large env values (certs/keys) without hitting the default ~64KB limit.
29	scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
30	for scanner.Scan() {
31		line := strings.TrimSpace(scanner.Text())
32		if line == "" || strings.HasPrefix(line, "#") {
33			continue
34		}
35
36		parts := strings.SplitN(line, "=", 2)
37		if len(parts) != 2 {
38			continue
39		}
40
41		key := strings.TrimSpace(parts[0])
42		rawValue := parts[1]
43
44		trimmedValue := strings.TrimSpace(rawValue)
45		value := trimmedValue
46
47		if len(trimmedValue) >= 2 {
48			if (strings.HasPrefix(trimmedValue, "\"") && strings.HasSuffix(trimmedValue, "\"")) ||
49				(strings.HasPrefix(trimmedValue, "'") && strings.HasSuffix(trimmedValue, "'")) {
50				value = trimmedValue[1 : len(trimmedValue)-1]
51			}
52		}
53
54		if key != "" {
55			secrets[key] = value
56		}
57	}
58
59	if err := scanner.Err(); err != nil {
60		return nil, err
61	}
62
63	return secrets, nil
64}
65
66// ValidateEnvKey validates an env key for storage.
67func ValidateEnvKey(key string) error {
68	if key == "" {
69		return ErrInvalidEnvKey
70	}
71	if strings.Contains(key, "..") || strings.ContainsAny(key, "/\\") {
72		return ErrPathTraversal
73	}
74	if !envKeyRegex.MatchString(key) {
75		return ErrInvalidEnvKey
76	}
77	return nil
78}
79
80// ValidateContainerName validates a container name for attachment storage.
81// Container names can contain alphanumeric characters, hyphens, and underscores,
82// but must start with a letter.
83func ValidateContainerName(name string) error {
84	if name == "" {
85		return ErrInvalidContainerName
86	}
87	if strings.Contains(name, "..") || strings.ContainsAny(name, "/\\") {
88		return ErrPathTraversal
89	}
90	if !containerNameRegex.MatchString(name) {
91		return ErrInvalidContainerName
92	}
93	return nil
94}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close