Skip to content

strconv: Unquote preserves literal carriage returns in raw string literals #15997

@mdempsky

Description

@mdempsky

Package strconv says:

Unquote interprets s as a single-quoted, double-quoted, or backquoted Go string literal, returning the string value that s quotes.

I understand "backquoted Go string literal" to mean what the Go spec calls a "raw string literal". Also, according to the Go spec:

Carriage return characters ('\r') inside raw string literals are discarded from the raw string value.

However, it seems that strconv.Unquote keeps carriage return characters rather than discarding them: https://play.golang.org/p/G-4x0-Mdop (Note that the \r escape sequence is interpreted by the Go interpreted string literal, so the string value seen by strconv.Unquote is the three byte sequence: GRAVE ACCENT, CARRIAGE RETURN, GRAVE ACCENT.)

It may be too late to change strconv.Unquote's behavior, but perhaps the existing behavior can be better documented at least.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions