diff --git a/internal/auth/ldap/config.go b/internal/auth/ldap/config.go index db666cde8..79840ee46 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 0bfe6c203..3c0f3b04c 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 f1fc04aa0..b53c66d61 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 289bcb28b..adc755878 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, "&", "&", -1) - s = strings.Replace(s, "<", "<", -1) - s = strings.Replace(s, ">", ">", -1) + s = strings.ReplaceAll(s, "&", "&") + s = strings.ReplaceAll(s, "<", "<") + s = strings.ReplaceAll(s, ">", ">") return s } func SlackShortTextFormatter(s string) string { s = strings.Split(s, "\n")[0] // replace & < > - s = strings.Replace(s, "&", "&", -1) - s = strings.Replace(s, "<", "<", -1) - s = strings.Replace(s, ">", ">", -1) + s = strings.ReplaceAll(s, "&", "&") + s = strings.ReplaceAll(s, "<", "<") + s = strings.ReplaceAll(s, ">", ">") return s } diff --git a/internal/db/wiki.go b/internal/db/wiki.go index f2276b61b..03e3a48d8 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 fbcab4f37..5aa14a9b2 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(`%s`, conf.Server.Subpath, m[1:], m)), -1) + rawBytes = bytes.ReplaceAll(rawBytes, m, []byte(fmt.Sprintf(`%s`, 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(``), -1) + p = bytes.ReplaceAll(p, []byte("\n"), []byte(`
`)) } c.Data["FileContent"] = string(p) } diff --git a/internal/template/template.go b/internal/template/template.go index dcb56639e..2ed0315ce 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 "
". func NewLine2br(raw string) string { - return strings.Replace(raw, "\n", "
", -1) + return strings.ReplaceAll(raw, "\n", "
") } func Sha1(str string) string {