@@ -30,20 +30,31 @@ func IsPackage(s string) bool {
30
30
return false
31
31
}
32
32
33
- // This goes off the assumption that file names may not have a `:` in their
34
- // name in cue.
35
- // A filename must have an extension or be preceded by a qualifier argument.
36
- // So strings of the form foo/bar:baz, where bar is a valid identifier and
37
- // absolute package
38
- if p := strings .LastIndexByte (s , ':' ); p > 0 {
39
- if ! ast .IsValidIdent (s [p + 1 :]) {
33
+ ip := ast .ParseImportPath (s )
34
+ if ip .ExplicitQualifier {
35
+ if ! ast .IsValidIdent (ip .Qualifier ) || strings .Contains (ip .Path , ":" ) || ip .Path == "-" {
36
+ // TODO potentially widen the scope of "file-like"
37
+ // paths here to include more invalid package paths?
40
38
return false
41
39
}
42
- // For a non-pkg, the part before : may only be lowercase and '+'.
43
- // In addition, a package necessarily must have a slash of some form.
44
- return strings .ContainsAny (s [:p ], `/.\` )
40
+ // If it's got an explicit qualifier, the path has a colon in
41
+ // which isn't generally allowed in CUE file names.
42
+ return true
43
+ }
44
+ if ip .Version != "" {
45
+ if strings .Contains (ip .Version , "/" ) {
46
+ // We'll definitely not allow slashes in the version string
47
+ // so treat it as a file name.
48
+ return false
49
+ }
50
+ // Looks like an explicit version suffix.
51
+ // Deliberately leave the syntax fairly open so that
52
+ // we get reasonable error messages when invalid version
53
+ // queries are specified.
54
+ return true
45
55
}
46
56
57
+ // No version and no qualifier.
47
58
// Assuming we terminate search for packages once a scoped qualifier is
48
59
// found, we know that any file without an extension (except maybe '-')
49
60
// is invalid. We can therefore assume it is a package.
0 commit comments