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

Wrong character is produced when indent contains full-width (zenkaku) space #6

Closed
makenowjust opened this issue Aug 23, 2019 · 1 comment
Assignees
Labels

Comments

@makenowjust
Copy link
Owner

Describe the bug

Wrong character is produced by heredoc.Doc function when indent contains full-width (zenkaku, u+3000) space.

To Reproduce

With:

package main

import (
	"fmt"

	"github.com/MakeNowJust/heredoc"
)

func main() {
	fmt.Printf("%#+v\n", heredoc.Doc("\n\u3000hello"))
}

Shows this result: "\x80\x80hello". "\x80" is wrong character.

Expected behavior

"hello" is correct result.

@makenowjust makenowjust self-assigned this Aug 23, 2019
@makenowjust
Copy link
Owner Author

makenowjust commented Aug 23, 2019

This bugs comes from using unicode.IsSpace, and Go's string slice counts its size as bytes, not as runes.

Package heredoc is used for writing raw string as heredoc-like, so it should follow Go language spec with respect to space character.

Go language spec says these characters are treated as space:

  • spaces U+0020
  • horizontal tabs U+0009
  • carriage returns U+000D
  • newlines U+000A

Newlines and carriage returns are known as newline character. As a conclusion, heredoc should treat only spaces and horizontal tabs as indent characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant