@@ -432,7 +432,10 @@ func loadModFile(ctx context.Context) (rs *Requirements, needCommit bool) {
432
432
initTarget (f .Module .Mod )
433
433
index = indexModFile (data , f , fixed )
434
434
435
- if err := checkModulePathLax (f .Module .Mod .Path ); err != nil {
435
+ if err := module .CheckImportPath (f .Module .Mod .Path ); err != nil {
436
+ if pathErr , ok := err .(* module.InvalidPathError ); ok {
437
+ pathErr .Kind = "module"
438
+ }
436
439
base .Fatalf ("go: %v" , err )
437
440
}
438
441
@@ -492,7 +495,15 @@ func CreateModFile(ctx context.Context, modPath string) {
492
495
if err != nil {
493
496
base .Fatalf ("go: %v" , err )
494
497
}
495
- } else if err := checkModulePathLax (modPath ); err != nil {
498
+ } else if err := module .CheckImportPath (modPath ); err != nil {
499
+ if pathErr , ok := err .(* module.InvalidPathError ); ok {
500
+ pathErr .Kind = "module"
501
+ // Same as build.IsLocalPath()
502
+ if pathErr .Path == "." || pathErr .Path == ".." ||
503
+ strings .HasPrefix (pathErr .Path , "./" ) || strings .HasPrefix (pathErr .Path , "../" ) {
504
+ pathErr .Err = errors .New ("is a local import path" )
505
+ }
506
+ }
496
507
base .Fatalf ("go: %v" , err )
497
508
}
498
509
@@ -536,49 +547,6 @@ func CreateModFile(ctx context.Context, modPath string) {
536
547
}
537
548
}
538
549
539
- // checkModulePathLax checks that the path meets some minimum requirements
540
- // to avoid confusing users or the module cache. The requirements are weaker
541
- // than those of module.CheckPath to allow room for weakening module path
542
- // requirements in the future, but strong enough to help users avoid significant
543
- // problems.
544
- func checkModulePathLax (p string ) error {
545
- // TODO(matloob): Replace calls of this function in this CL with calls
546
- // to module.CheckImportPath once it's been laxened, if it becomes laxened.
547
- // See golang.org/issue/29101 for a discussion about whether to make CheckImportPath
548
- // more lax or more strict.
549
-
550
- errorf := func (format string , args ... interface {}) error {
551
- return fmt .Errorf ("invalid module path %q: %s" , p , fmt .Sprintf (format , args ... ))
552
- }
553
-
554
- // Disallow shell characters " ' * < > ? ` | to avoid triggering bugs
555
- // with file systems and subcommands. Disallow file path separators : and \
556
- // because path separators other than / will confuse the module cache.
557
- // See fileNameOK in golang.org/x/mod/module/module.go.
558
- shellChars := "`" + `"'*<>?|`
559
- fsChars := `\:`
560
- if i := strings .IndexAny (p , shellChars ); i >= 0 {
561
- return errorf ("contains disallowed shell character %q" , p [i ])
562
- }
563
- if i := strings .IndexAny (p , fsChars ); i >= 0 {
564
- return errorf ("contains disallowed path separator character %q" , p [i ])
565
- }
566
-
567
- // Ensure path.IsAbs and build.IsLocalImport are false, and that the path is
568
- // invariant under path.Clean, also to avoid confusing the module cache.
569
- if path .IsAbs (p ) {
570
- return errorf ("is an absolute path" )
571
- }
572
- if build .IsLocalImport (p ) {
573
- return errorf ("is a local import path" )
574
- }
575
- if path .Clean (p ) != p {
576
- return errorf ("is not clean" )
577
- }
578
-
579
- return nil
580
- }
581
-
582
550
// fixVersion returns a modfile.VersionFixer implemented using the Query function.
583
551
//
584
552
// It resolves commit hashes and branch names to versions,
@@ -918,14 +886,8 @@ func findModulePath(dir string) (string, error) {
918
886
}
919
887
if rel := search .InDir (dir , filepath .Join (gpdir , "src" )); rel != "" && rel != "." {
920
888
path := filepath .ToSlash (rel )
921
- // TODO(matloob): replace this with module.CheckImportPath
922
- // once it's been laxened.
923
- // Only checkModulePathLax here. There are some unpublishable
924
- // module names that are compatible with checkModulePathLax
925
- // but they already work in GOPATH so don't break users
926
- // trying to do a build with modules. gorelease will alert users
927
- // publishing their modules to fix their paths.
928
- if err := checkModulePathLax (path ); err != nil {
889
+ // gorelease will alert users publishing their modules to fix their paths.
890
+ if err := module .CheckImportPath (path ); err != nil {
929
891
badPathErr = err
930
892
break
931
893
}
0 commit comments