Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix textual printing of byte slices #266

Merged
merged 1 commit into from
Jul 19, 2021
Merged

Fix textual printing of byte slices #266

merged 1 commit into from
Jul 19, 2021

Conversation

dsnet
Copy link
Collaborator

@dsnet dsnet commented Jul 19, 2021

There are two bugs being fixed:

  1. The hueristic for whether a slice of byte looks like text
    should check whether a rune IsPrint OR IsSpace, and not both.
    Only a single rune (i.e., U+0020) ever satisfies both conditions.

    Previously, it would print as:

    MyBytes{0x68, 0x65, 0x6c, 0x6c, 0x6f}
    

    and now it would now print as:

    MyBytes(MyBytes("hello"))
    
  2. If we're printing as string, then we should set skipType=true
    since we already explicitly format the value with the type.

    Previously, it would print as:

    MyBytes(MyBytes("hello"))
    

    and now it would now print as:

    MyBytes("hello")
    

There are two bugs being fixed:

1.  The hueristic for whether a slice of byte looks like text
    should check whether a rune IsPrint OR IsSpace, and not both.
    Only a single rune (i.e., U+0020) ever satisfies both conditions.

    Previously, it would print as:
        MyBytes{0x68, 0x65, 0x6c, 0x6c, 0x6f}
    and now it would now print as:
        MyBytes(MyBytes("hello"))

2.  If we're printing as string, then we should set skipType=true
    since we already explicitly format the value with the type.

    Previously, it would print as:
        MyBytes(MyBytes("hello"))
    and now it would now print as:
        MyBytes("hello")
@dsnet
Copy link
Collaborator Author

dsnet commented Jul 19, 2021

\cc @neild.

@neild neild merged commit 402949e into google:master Jul 19, 2021
@dsnet dsnet deleted the fix-format branch July 19, 2021 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants