Skip to content

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

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{"", "", ""}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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