diff --git a/src/go/printer/printer.go b/src/go/printer/printer.go index 5a6127c6b40..e84fb372b00 100644 --- a/src/go/printer/printer.go +++ b/src/go/printer/printer.go @@ -311,7 +311,7 @@ func (p *printer) writeString(pos token.Position, s string, isLit bool) { var li int // index of last newline; valid if nlines > 0 for i := 0; i < len(s); i++ { // Raw string literals may contain any character except back quote (`). - if ch := s[i]; ch == '\n' || ch == '\f' { + if ch := s[i]; ch == '\n' { // account for line break nlines++ li = i diff --git a/src/go/printer/printer_test.go b/src/go/printer/printer_test.go index 2a9c8be3003..19fdd44f37b 100644 --- a/src/go/printer/printer_test.go +++ b/src/go/printer/printer_test.go @@ -16,6 +16,7 @@ import ( "io" "os" "path/filepath" + "strings" "testing" "time" ) @@ -863,3 +864,28 @@ func TestEmptyDecl(t *testing.T) { // issue 63566 } } } + +func TestIssue69858(t *testing.T) { + cases := []string{ + "package A\nimport(\"a\"/*\f*/\n\"bb\")", + "package A\nfunc test() {\"a\"/*\f*/\n\"bb\"}", + } + for _, src := range cases { + fset := token.NewFileSet() + f, err := parser.ParseFile(fset, "test.go", src, parser.ParseComments|parser.SkipObjectResolution) + if err != nil { + t.Fatal(err) + } + + var out strings.Builder + if err := Fprint(&out, fset, f); err != nil { + t.Fatal(err) + } + + _, err = parser.ParseFile(fset, "test.go", out.String(), parser.ParseComments|parser.SkipObjectResolution) + if err != nil { + t.Logf("source:\n%s\nformatted as:\n%s", src, out.String()) + t.Error(err) + } + } +}