From 01aa517119c24846fcf9a8d5d4ec278d2abfb63d Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:42:11 -0800 Subject: [PATCH] Match typed-path lint URL detection to runtime roots Drive-like prefixes are URL roots unless they satisfy the runtime's DOS root rules. Treating every second-character colon as a drive bypasses URL query and fragment validation for strings that runtime rejects. Require a letter and a rooted drive suffix, reuse the URL classifier for suffix parsing, and cover rejected queries alongside accepted drive and URL edge cases in the analyzer fixtures. --- tools/customlint/testdata/typedpaths/typedpaths.go | 8 ++++++++ .../testdata/typedpaths/typedpaths.go.golden | 14 ++++++++++++++ tools/customlint/typedpaths.go | 9 +++------ 3 files changed, 25 insertions(+), 6 deletions(-) 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, "://")