@@ -104,6 +104,40 @@ func fileNameOK(r rune) bool {
104
104
return unicode .IsLetter (r )
105
105
}
106
106
107
+ // CheckPathWithoutVersion is like CheckPath except that
108
+ // it expects a module path without a major version.
109
+ func CheckPathWithoutVersion (basePath string ) (err error ) {
110
+ if _ , _ , ok := SplitPathVersion (basePath ); ok {
111
+ return fmt .Errorf ("module path inappropriately contains major version" )
112
+ }
113
+ if err := checkPath (basePath , modulePath ); err != nil {
114
+ return err
115
+ }
116
+ i := strings .Index (basePath , "/" )
117
+ if i < 0 {
118
+ i = len (basePath )
119
+ }
120
+ if i == 0 {
121
+ return fmt .Errorf ("leading slash" )
122
+ }
123
+ if ! strings .Contains (basePath [:i ], "." ) {
124
+ return fmt .Errorf ("missing dot in first path element" )
125
+ }
126
+ if basePath [0 ] == '-' {
127
+ return fmt .Errorf ("leading dash in first path element" )
128
+ }
129
+ for _ , r := range basePath [:i ] {
130
+ if ! firstPathOK (r ) {
131
+ return fmt .Errorf ("invalid char %q in first path element" , r )
132
+ }
133
+ }
134
+ // Sanity check agreement with OCI specs.
135
+ if ! basePathPat .MatchString (basePath ) {
136
+ return fmt .Errorf ("non-conforming path %q" , basePath )
137
+ }
138
+ return nil
139
+ }
140
+
107
141
// CheckPath checks that a module path is valid.
108
142
// A valid module path is a valid import path, as checked by CheckImportPath,
109
143
// with three additional constraints.
@@ -135,32 +169,9 @@ func CheckPath(mpath string) (err error) {
135
169
if semver .Major (vers ) != vers {
136
170
return fmt .Errorf ("path can contain major version only" )
137
171
}
138
-
139
- if err := checkPath (basePath , modulePath ); err != nil {
172
+ if err := CheckPathWithoutVersion (basePath ); err != nil {
140
173
return err
141
174
}
142
- i := strings .Index (basePath , "/" )
143
- if i < 0 {
144
- i = len (basePath )
145
- }
146
- if i == 0 {
147
- return fmt .Errorf ("leading slash" )
148
- }
149
- if ! strings .Contains (basePath [:i ], "." ) {
150
- return fmt .Errorf ("missing dot in first path element" )
151
- }
152
- if basePath [0 ] == '-' {
153
- return fmt .Errorf ("leading dash in first path element" )
154
- }
155
- for _ , r := range basePath [:i ] {
156
- if ! firstPathOK (r ) {
157
- return fmt .Errorf ("invalid char %q in first path element" , r )
158
- }
159
- }
160
- // Sanity check agreement with OCI specs.
161
- if ! basePathPat .MatchString (basePath ) {
162
- return fmt .Errorf ("non-conforming path %q" , basePath )
163
- }
164
175
if ! tagPat .MatchString (vers ) {
165
176
return fmt .Errorf ("non-conforming version %q" , vers )
166
177
}
0 commit comments