Skip to content

Commit

Permalink
Recognize \r as a valid space separator
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 695757909
  • Loading branch information
txtpbfmt-copybara-robot committed Nov 12, 2024
1 parent 5c07d7c commit 20d2c9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ func removeDeleted(nodes []*ast.Node) []*ast.Node {
}

var (
spaceSeparators = []byte(" \t\n")
valueSeparators = []byte(" \t\n{}:,[]<>;#")
spaceSeparators = []byte(" \t\n\r")
valueSeparators = []byte(" \t\n\r{}:,[]<>;#")
)

// Parse returns a tree representation of a textproto file.
Expand Down
8 changes: 7 additions & 1 deletion parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,13 @@ a, b,
c
# txtpbfmt: on
]
`}}
`}, {
name: "carriage return \\r is formatted away",
in: `foo: "bar"` + "\r" + `baz: "bat"` + "\r",
out: `foo: "bar"` + "\n" + `baz: "bat"` + "\n"}, {
name: "Windows-style newline \\r\\n is formatted away",
in: `foo: "bar"` + "\r\n" + `baz: "bat"` + "\r\n",
out: `foo: "bar"` + "\n" + `baz: "bat"` + "\n"}}
for _, input := range inputs {
out, err := Format([]byte(input.in))
if err != nil {
Expand Down

0 comments on commit 20d2c9e

Please sign in to comment.