Skip to content

Check files improve path normalization#382

Open
inqrphl wants to merge 2 commits into
mainfrom
check-files-improve-path-normalization
Open

Check files improve path normalization#382
inqrphl wants to merge 2 commits into
mainfrom
check-files-improve-path-normalization

Conversation

@inqrphl
Copy link
Copy Markdown
Contributor

@inqrphl inqrphl commented May 28, 2026

  1. path normalization function cleans up the paths better, by switching to filesystem separator first.

normalized path is used for depth calculation. the depth is the count difference of filesystem separators

it is also used to check if an filesystem item is inside another filesystem item.

for windows, the paths could be specified using forward slashes like this: "C:/Windows". This meant that this block in normalizePath would run and append a backward slash making the path "C:/Windows" .

	if runtime.GOOS == "windows" {
		// C: -> C:\
		if len(path) == 2 && unicode.IsUpper(rune(path[0])) && path[1] == ':' {
			// Ensure drive letters always have a backslash: "C:" -> "C:\"
			return path + string(os.PathSeparator)
		}
		// "C:example" -> "C:\example".
		if len(path) >= 3 && unicode.IsUpper(rune(path[0])) && path[1] == ':' && path[2] != '\\' {
			winBasePath := path[:2] + string('\\') + path[2:]

			return winBasePath
		}
	}

Discovered files would look like "C:/Windows/test.txt" and would not be considered as under "C:/Windows", breaking the check.

convert forward slashes to backward slashes using filepath.FromSlash before that block.

  1. For all platforms:
    Replace groups of separators into a single separator. This prevents a////b////c from having higher depth than a/b/c .

Fixing this issue as well, it did not come from a bug report but found while looking through the code.

inqrphl added 2 commits May 27, 2026 15:17
path normalization function cleans up the paths, and is then used for depth calculation.

for windows, convert forward slashes to backward slashes using filepath.FromSlash

for all systems, replace groups of seperators into a single seperator. this prevents a////b////c from having higher depth than a/b/c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant