]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: permit Unicode spaces in (expanded) package paths
authorRobert Griesemer <gri@golang.org>
Fri, 16 Jun 2017 21:48:38 +0000 (14:48 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 19 Jun 2017 16:59:58 +0000 (16:59 +0000)
This doesn't change the existing restriction with disallows
spaces in import paths (as found in an import declaration).
It simply permits packages to be under a directory name that
may contain spaces.

Verified manually that it works. This could use a test, but the
change is trivial. We also can't use the existing test framework
(under test/) because the way those tests are run with test/run.go,
the mechanims for compiling a directory, even if it contains blanks
it its name, does't produce compiler paths with blanks
(the compilation is local).

Fixes #20306.

Change-Id: I6cbffb86c3394347897c3c94b110da0aadc5bfdf
Reviewed-on: https://go-review.googlesource.com/46001
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/subr.go

index 282f8766e2b3dd9c3600c57368c579a8476b7bb0..29629620898debbd1c3fdbcc35b9ded969f419fc 100644 (file)
@@ -285,7 +285,7 @@ func (p *importer) pkg() *types.Pkg {
        }
 
        // we should never see a bad import path
-       if isbadimport(path) {
+       if isbadimport(path, true) {
                p.formatErrorf("bad package path %q for package %s", path, name)
        }
 
index 57c6600b153c631925e19b1018cb16fa7d93fabc..5e3030297009c960464646b9c5ded275086ad138 100644 (file)
@@ -891,7 +891,7 @@ func importfile(f *Val) *types.Pkg {
                return nil
        }
 
-       if isbadimport(path_) {
+       if isbadimport(path_, false) {
                return nil
        }
 
@@ -935,7 +935,7 @@ func importfile(f *Val) *types.Pkg {
                }
                path_ = path.Join(prefix, path_)
 
-               if isbadimport(path_) {
+               if isbadimport(path_, true) {
                        return nil
                }
        }
index 566403bcded85544cec0d63fbadb068260165374..d79789c4febca2f02f429fe3fad93c4dc85aa683 100644 (file)
@@ -1969,7 +1969,7 @@ var reservedimports = []string{
        "type",
 }
 
-func isbadimport(path string) bool {
+func isbadimport(path string, allowSpace bool) bool {
        if strings.Contains(path, "\x00") {
                yyerror("import path contains NUL")
                return true
@@ -1998,7 +1998,7 @@ func isbadimport(path string) bool {
                        return true
                }
 
-               if unicode.IsSpace(r) {
+               if !allowSpace && unicode.IsSpace(r) {
                        yyerror("import path contains space character: %q", path)
                        return true
                }