Skip to content

strings: zero-length string Split()s to non-zero number of substrings #1399

@masiulaniec

Description

@masiulaniec
package main

import (
        "strings"
        "fmt"
)

func main() {
        fmt.Printf("%#v\t%#v\n", "", strings.Split("", ":", -1))
        fmt.Printf("%#v\t%#v\n", ":", strings.Split(":", ":", -1))
        fmt.Printf("%#v\t%#v\n", "::", strings.Split("::", ":", -1))
}


What is the expected output?

""      []string{}
":"     []string{"", ""}
"::"    []string{"", "", ""}


What do you see instead?

""      []string{""}
":"     []string{"", ""}
"::"    []string{"", "", ""}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions