Skip to content

strings: use a closure for FieldsFunc may result in a panic #8738

@jbardin

Description

@jbardin
go1.3.1

FieldsFunc runs over the runes twice. If a closure is used, and the underlying state
does't match the first run, there may be a panic.

The following panics (http://play.golang.org/p/P1MKh8GKaF)

    state := false
    f := func(c rune) bool {
        switch c {
        case '1':
            fmt.Println(state)
            state = !state
            return state
        default:
            fmt.Println("true")
            return true
        }
    }
    strings.FieldsFunc(" 1", f)




This should be safe from panics, or at least clearly document that FieldsFunc is run
twice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions