]> Cypherpunks repositories - gostls13.git/commitdiff
gc: escape unicode BOM in exported string literals
authorVolker Dobler <dr.volker.dobler@gmail.com>
Thu, 11 Apr 2013 18:45:18 +0000 (11:45 -0700)
committerRob Pike <r@golang.org>
Thu, 11 Apr 2013 18:45:18 +0000 (11:45 -0700)
Fixes #5260.

R=golang-dev, minux.ma, 0xjnml, r
CC=golang-dev
https://golang.org/cl/8658043

src/cmd/gc/fmt.c
test/fixedbugs/issue5260.dir/a.go [new file with mode: 0644]
test/fixedbugs/issue5260.dir/b.go [new file with mode: 0644]
test/fixedbugs/issue5260.go [new file with mode: 0644]

index 8a14aa2df959a12d8b59069c7e78975b924571c9..35f01a5c2628da0bccb6ad39fe5da02fe41753d9 100644 (file)
@@ -443,6 +443,9 @@ Zconv(Fmt *fp)
                        fmtrune(fp, '\\');
                        fmtrune(fp, r);
                        break;
+               case 0xFEFF: // BOM, basically disallowed in source code
+                       fmtstrcpy(fp, "\\uFEFF");
+                       break;
                }
        }
        return 0;
diff --git a/test/fixedbugs/issue5260.dir/a.go b/test/fixedbugs/issue5260.dir/a.go
new file mode 100644 (file)
index 0000000..5a2c99f
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package a
+
+const BOM = "\uFEFF"
diff --git a/test/fixedbugs/issue5260.dir/b.go b/test/fixedbugs/issue5260.dir/b.go
new file mode 100644 (file)
index 0000000..299b75e
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "./a"
+
+func main() {
+       _ = a.BOM
+}
diff --git a/test/fixedbugs/issue5260.go b/test/fixedbugs/issue5260.go
new file mode 100644 (file)
index 0000000..11fd5d0
--- /dev/null
@@ -0,0 +1,10 @@
+// rundir
+
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 5260: Unicode BOM in exported string constant
+// cannot be read back during package import.
+
+package ignored