Skip to content

bytes: ReplaceAll returns nil slice when empty slice is given #46415

@KaitoHH

Description

@KaitoHH

What version of Go are you using (go version)?

$ go version
go version go1.14.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package main

import (
	"bytes"
	"fmt"
)

func main() {
	old := []byte("")
	b := bytes.ReplaceAll(old, []byte("oink"), []byte("moo"))
	fmt.Println(old == nil)
	fmt.Println(b == nil)
}

What did you expect to see?

false
true

the call of bytes.ReplaceAll on an empty slice should also return an empty slice. However, it returns nil

What did you see instead?

false
false

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions