diff --git a/tools/customlint/testdata/typedpaths/typedpaths.go b/tools/customlint/testdata/typedpaths/typedpaths.go index 4f4f42ac9a8d2..ad83cb40b2611 100644 --- a/tools/customlint/testdata/typedpaths/typedpaths.go +++ b/tools/customlint/testdata/typedpaths/typedpaths.go @@ -106,6 +106,9 @@ func badConstructorConstants() { _ = tspath.RootedFilePathFromAbsolute("relative/path") _ = tspath.RootedDirectoryPathFromAbsolute("relative/path") _ = tspath.RootedPathFromNormalized("") + _ = tspath.RootedPathFromNormalized("c:d://server/a?b") + _ = tspath.RootedPathFromNormalized("1:x://server/a#b") + _ = tspath.RootedPathFromAbsolute("1://server/a?b") _ = tspath.RootedFilePathFromNormalized("/project/../file.ts") _ = tspath.RootedDirectoryPathFromNormalized("/project/") _ = tspath.RelativePathFromNormalized("/project/file.ts") @@ -132,6 +135,11 @@ func goodConstructorConstants(dynamic string) { _ = tspath.RootedDirectoryPathFromAbsolute("file:///project") _ = tspath.RootedPathFromNormalized("/") _ = tspath.RootedPathFromNormalized("FILE:///C:/") + _ = tspath.RootedPathFromNormalized("C:/a?b#c") + _ = tspath.RootedPathFromAbsolute("c:/d://server/a?b") + _ = tspath.RootedPathFromNormalized("c:d://server/a") + _ = tspath.RootedPathFromNormalized("1:x://server/a") + _ = tspath.RootedPathFromNormalized("1://server/a") _ = tspath.RootedFilePathFromNormalized(constantRoot + "/file.ts") _ = tspath.RootedDirectoryPathFromNormalized("^/untitled") _ = tspath.RelativePathFromNormalized("../project/") diff --git a/tools/customlint/testdata/typedpaths/typedpaths.go.golden b/tools/customlint/testdata/typedpaths/typedpaths.go.golden index f2a26b05106d6..63153d2fb91b3 100644 --- a/tools/customlint/testdata/typedpaths/typedpaths.go.golden +++ b/tools/customlint/testdata/typedpaths/typedpaths.go.golden @@ -178,6 +178,15 @@ _ = tspath.RootedPathFromNormalized("") ~ !!! typedpaths: constant argument to RootedPathFromNormalized must be rooted and normalized + _ = tspath.RootedPathFromNormalized("c:d://server/a?b") + ~ +!!! typedpaths: constant argument to RootedPathFromNormalized must be rooted and normalized + _ = tspath.RootedPathFromNormalized("1:x://server/a#b") + ~ +!!! typedpaths: constant argument to RootedPathFromNormalized must be rooted and normalized + _ = tspath.RootedPathFromAbsolute("1://server/a?b") + ~ +!!! typedpaths: constant argument to RootedPathFromAbsolute must be absolute _ = tspath.RootedFilePathFromNormalized("/project/../file.ts") ~ !!! typedpaths: constant argument to RootedFilePathFromNormalized must be rooted and normalized @@ -238,6 +247,11 @@ _ = tspath.RootedDirectoryPathFromAbsolute("file:///project") _ = tspath.RootedPathFromNormalized("/") _ = tspath.RootedPathFromNormalized("FILE:///C:/") + _ = tspath.RootedPathFromNormalized("C:/a?b#c") + _ = tspath.RootedPathFromAbsolute("c:/d://server/a?b") + _ = tspath.RootedPathFromNormalized("c:d://server/a") + _ = tspath.RootedPathFromNormalized("1:x://server/a") + _ = tspath.RootedPathFromNormalized("1://server/a") _ = tspath.RootedFilePathFromNormalized(constantRoot + "/file.ts") _ = tspath.RootedDirectoryPathFromNormalized("^/untitled") _ = tspath.RelativePathFromNormalized("../project/") diff --git a/tools/customlint/typedpaths.go b/tools/customlint/typedpaths.go index b6d52450c8062..aa29820db595e 100644 --- a/tools/customlint/typedpaths.go +++ b/tools/customlint/typedpaths.go @@ -340,7 +340,8 @@ func isLiteralURLPath(path string) bool { if path == "" || path[0] == '/' || path[0] == '\\' || - len(path) > 1 && path[1] == ':' || + len(path) > 1 && isLiteralVolumeCharacter(path[0]) && path[1] == ':' && + (len(path) == 2 || path[2] == '/' || path[2] == '\\') || strings.HasPrefix(path, "^/") { return false } @@ -474,11 +475,7 @@ func isLiteralCanonicalPath(path string) bool { } func literalURLPathPart(path string) string { - if path == "" || - path[0] == '/' || - path[0] == '\\' || - len(path) > 1 && path[1] == ':' || - strings.HasPrefix(path, "^/") { + if !isLiteralURLPath(path) { return path } schemeEnd := strings.Index(path, "://")