aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/auth/ldap/config.go6
-rw-r--r--internal/cmd/import.go2
-rw-r--r--internal/db/ssh_key.go7
-rw-r--r--internal/db/webhook_slack.go12
-rw-r--r--internal/db/wiki.go2
-rw-r--r--internal/markup/markup.go7
-rw-r--r--internal/route/install.go4
-rw-r--r--internal/route/repo/editor.go2
-rw-r--r--internal/route/repo/view.go2
-rw-r--r--internal/template/template.go2
10 files changed, 22 insertions, 24 deletions
diff --git a/internal/auth/ldap/config.go b/internal/auth/ldap/config.go
index db666cde..79840ee4 100644
--- a/internal/auth/ldap/config.go
+++ b/internal/auth/ldap/config.go
@@ -72,7 +72,7 @@ func (c *Config) sanitizedUserQuery(username string) (string, bool) {
return "", false
}
- return strings.Replace(c.Filter, "%s", username, -1), true
+ return strings.ReplaceAll(c.Filter, "%s", username), true
}
func (c *Config) sanitizedUserDN(username string) (string, bool) {
@@ -83,7 +83,7 @@ func (c *Config) sanitizedUserDN(username string) (string, bool) {
return "", false
}
- return strings.Replace(c.UserDN, "%s", username, -1), true
+ return strings.ReplaceAll(c.UserDN, "%s", username), true
}
func (c *Config) sanitizedGroupFilter(group string) (string, bool) {
@@ -112,7 +112,7 @@ func (c *Config) findUserDN(l *ldap.Conn, name string) (string, bool) {
log.Trace("Search for LDAP user: %s", name)
if len(c.BindDN) > 0 && len(c.BindPassword) > 0 {
// Replace placeholders with username
- bindDN := strings.Replace(c.BindDN, "%s", name, -1)
+ bindDN := strings.ReplaceAll(c.BindDN, "%s", name)
err := l.Bind(bindDN, c.BindPassword)
if err != nil {
log.Trace("LDAP: Failed to bind as BindDN '%s': %v", bindDN, err)
diff --git a/internal/cmd/import.go b/internal/cmd/import.go
index 0bfe6c20..3c0f3b04 100644
--- a/internal/cmd/import.go
+++ b/internal/cmd/import.go
@@ -95,7 +95,7 @@ func runImportLocale(c *cli.Context) error {
if idx > -1 && line[len(line)-1] == '"' {
// We still want the "=" sign
line = append(line[:idx+1], line[idx+2:len(line)-1]...)
- line = bytes.Replace(line, escapedQuotes, regularQuotes, -1)
+ line = bytes.ReplaceAll(line, escapedQuotes, regularQuotes)
}
_, _ = tw.Write(line)
_, _ = tw.WriteString("\n")
diff --git a/internal/db/ssh_key.go b/internal/db/ssh_key.go
index f1fc04aa..b53c66d6 100644
--- a/internal/db/ssh_key.go
+++ b/internal/db/ssh_key.go
@@ -112,10 +112,10 @@ func parseKeyString(content string) (string, error) {
// Transform all legal line endings to a single "\n"
// Replace all windows full new lines ("\r\n")
- content = strings.Replace(content, "\r\n", "\n", -1)
+ content = strings.ReplaceAll(content, "\r\n", "\n")
// Replace all windows half new lines ("\r"), if it happen not to match replace above
- content = strings.Replace(content, "\r", "\n", -1)
+ content = strings.ReplaceAll(content, "\r", "\n")
// Replace ending new line as its may cause unwanted behaviour (extra line means not a single line key | OpenSSH key)
content = strings.TrimRight(content, "\n")
@@ -374,8 +374,7 @@ func checkKeyContent(content string) error {
func addKey(e Engine, key *PublicKey) (err error) {
// Calculate fingerprint.
- tmpPath := strings.Replace(path.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()),
- "id_rsa.pub"), "\\", "/", -1)
+ tmpPath := strings.ReplaceAll(path.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()), "id_rsa.pub"), "\\", "/")
_ = os.MkdirAll(path.Dir(tmpPath), os.ModePerm)
if err = ioutil.WriteFile(tmpPath, []byte(key.Content), 0644); err != nil {
return err
diff --git a/internal/db/webhook_slack.go b/internal/db/webhook_slack.go
index 289bcb28..adc75587 100644
--- a/internal/db/webhook_slack.go
+++ b/internal/db/webhook_slack.go
@@ -51,18 +51,18 @@ func (p *SlackPayload) JSONPayload() ([]byte, error) {
// see: https://api.slack.com/docs/formatting
func SlackTextFormatter(s string) string {
// replace & < >
- s = strings.Replace(s, "&", "&amp;", -1)
- s = strings.Replace(s, "<", "&lt;", -1)
- s = strings.Replace(s, ">", "&gt;", -1)
+ s = strings.ReplaceAll(s, "&", "&amp;")
+ s = strings.ReplaceAll(s, "<", "&lt;")
+ s = strings.ReplaceAll(s, ">", "&gt;")
return s
}
func SlackShortTextFormatter(s string) string {
s = strings.Split(s, "\n")[0]
// replace & < >
- s = strings.Replace(s, "&", "&amp;", -1)
- s = strings.Replace(s, "<", "&lt;", -1)
- s = strings.Replace(s, ">", "&gt;", -1)
+ s = strings.ReplaceAll(s, "&", "&amp;")
+ s = strings.ReplaceAll(s, "<", "&lt;")
+ s = strings.ReplaceAll(s, ">", "&gt;")
return s
}
diff --git a/internal/db/wiki.go b/internal/db/wiki.go
index f2276b61..03e3a48d 100644
--- a/internal/db/wiki.go
+++ b/internal/db/wiki.go
@@ -33,7 +33,7 @@ func ToWikiPageURL(name string) string {
// that are not belong to wiki repository.
func ToWikiPageName(urlString string) string {
name, _ := url.QueryUnescape(urlString)
- return strings.Replace(strings.TrimLeft(path.Clean("/"+name), "/"), "/", " ", -1)
+ return strings.ReplaceAll(strings.TrimLeft(path.Clean("/"+name), "/"), "/", " ")
}
// WikiCloneLink returns clone URLs of repository wiki.
diff --git a/internal/markup/markup.go b/internal/markup/markup.go
index fbcab4f3..5aa14a9b 100644
--- a/internal/markup/markup.go
+++ b/internal/markup/markup.go
@@ -155,8 +155,7 @@ func RenderSpecialLink(rawBytes []byte, urlPrefix string, metas map[string]strin
ms := MentionPattern.FindAll(rawBytes, -1)
for _, m := range ms {
m = m[bytes.Index(m, []byte("@")):]
- rawBytes = bytes.Replace(rawBytes, m,
- []byte(fmt.Sprintf(`<a href="%s/%s">%s</a>`, conf.Server.Subpath, m[1:], m)), -1)
+ rawBytes = bytes.ReplaceAll(rawBytes, m, []byte(fmt.Sprintf(`<a href="%s/%s">%s</a>`, conf.Server.Subpath, m[1:], m)))
}
rawBytes = RenderIssueIndexPattern(rawBytes, urlPrefix, metas)
@@ -216,7 +215,7 @@ func wrapImgWithLink(urlPrefix string, buf *bytes.Buffer, token html.Token) {
buf.WriteString(`">`)
if needPrepend {
- src = strings.Replace(urlPrefix+src, " ", "%20", -1)
+ src = strings.ReplaceAll(urlPrefix+src, " ", "%20")
buf.WriteString(`<img src="`)
buf.WriteString(src)
buf.WriteString(`"`)
@@ -347,7 +346,7 @@ func Render(typ Type, input interface{}, urlPrefix string, metas map[string]stri
panic(fmt.Sprintf("unrecognized input content type: %T", input))
}
- urlPrefix = strings.TrimRight(strings.Replace(urlPrefix, " ", "%20", -1), "/")
+ urlPrefix = strings.TrimRight(strings.ReplaceAll(urlPrefix, " ", "%20"), "/")
var rawHTML []byte
switch typ {
case TypeMarkdown:
diff --git a/internal/route/install.go b/internal/route/install.go
index 94c7dd2c..4a529655 100644
--- a/internal/route/install.go
+++ b/internal/route/install.go
@@ -240,7 +240,7 @@ func InstallPost(c *context.Context, f form.Install) {
}
// Test repository root path.
- f.RepoRootPath = strings.Replace(f.RepoRootPath, "\\", "/", -1)
+ f.RepoRootPath = strings.ReplaceAll(f.RepoRootPath, "\\", "/")
if err := os.MkdirAll(f.RepoRootPath, os.ModePerm); err != nil {
c.FormErr("RepoRootPath")
c.RenderWithErr(c.Tr("install.invalid_repo_path", err), INSTALL, &f)
@@ -248,7 +248,7 @@ func InstallPost(c *context.Context, f form.Install) {
}
// Test log root path.
- f.LogRootPath = strings.Replace(f.LogRootPath, "\\", "/", -1)
+ f.LogRootPath = strings.ReplaceAll(f.LogRootPath, "\\", "/")
if err := os.MkdirAll(f.LogRootPath, os.ModePerm); err != nil {
c.FormErr("LogRootPath")
c.RenderWithErr(c.Tr("install.invalid_log_root_path", err), INSTALL, &f)
diff --git a/internal/route/repo/editor.go b/internal/route/repo/editor.go
index 8f612a98..58536f5b 100644
--- a/internal/route/repo/editor.go
+++ b/internal/route/repo/editor.go
@@ -268,7 +268,7 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
OldTreeName: oldTreePath,
NewTreeName: f.TreePath,
Message: message,
- Content: strings.Replace(f.Content, "\r", "", -1),
+ Content: strings.ReplaceAll(f.Content, "\r", ""),
IsNewFile: isNewFile,
}); err != nil {
log.Error("Failed to update repo file: %v", err)
diff --git a/internal/route/repo/view.go b/internal/route/repo/view.go
index e9f340cb..89d6f86d 100644
--- a/internal/route/repo/view.go
+++ b/internal/route/repo/view.go
@@ -95,7 +95,7 @@ func renderDirectory(c *context.Context, treeLink string) {
c.Data["IsIPythonNotebook"] = true
c.Data["RawFileLink"] = c.Repo.RepoLink + "/raw/" + path.Join(c.Repo.BranchName, c.Repo.TreePath, readmeFile.Name())
default:
- p = bytes.Replace(p, []byte("\n"), []byte(`<br>`), -1)
+ p = bytes.ReplaceAll(p, []byte("\n"), []byte(`<br>`))
}
c.Data["FileContent"] = string(p)
}
diff --git a/internal/template/template.go b/internal/template/template.go
index dcb56639..2ed0315c 100644
--- a/internal/template/template.go
+++ b/internal/template/template.go
@@ -146,7 +146,7 @@ func Str2HTML(raw string) template.HTML {
// NewLine2br simply replaces "\n" to "<br>".
func NewLine2br(raw string) string {
- return strings.Replace(raw, "\n", "<br>", -1)
+ return strings.ReplaceAll(raw, "\n", "<br>")
}
func Sha1(str string) string {