Skip to content

Go1.12 strings.Map breaks package usage of strings.ToUpper and strings.ToLower #26

Closed
@cybrcodr

Description

@cybrcodr

Go1.12 CL https://golang.org/cl/131495 will break this package's use of upper() and lower() calls. This is exhibited in the following test failure ...

$ go version
go version go1.12beta1 linux/386
$ go test
--- FAIL: TestToGoName (0.03s)
    util_test.go:66:
                Error Trace:    util_test.go:66
                Error:          Not equal:
                                expected: "X日本語sample2Text"
                                actual  : "X�\xbf\xbd��本語sample2Text"

                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -X日本語sample2Text
                                +X�����本語sample2Text
                Test:           TestToGoName
    util_test.go:66:
                Error Trace:    util_test.go:66
                Error:          Not equal:
                                expected: "X日本語findThingByID"
                                actual  : "X�\xbf\xbd��本語findThingByID"

                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -X日本語findThingByID
                                +X�����本語findThingByID
                Test:           TestToGoName
FAIL
exit status 1

The issue has to do with this package passing in str[:1] to upper() and lower() assuming that slicing out the first byte is a valid unicode character and if not, the calls to strings.ToUpper or strings.ToLower will return back the same byte and hence can be reused. The new behavior of strings.ToUpper and strings.ToLower returns back utf8.RuneError if byte is not a valid unicode character instead and breaks the logic in callers when concatenating to another string slice.

For example -- https://github.com/go-openapi/swag/blob/v0.18.0/util.go#L332-L337.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @cybrcodr

      Issue actions

        Go1.12 strings.Map breaks package usage of strings.ToUpper and strings.ToLower · Issue #26 · go-openapi/swag