Method IsWithinDirectory(string, string, char, StringComparison)
Tests whether a already-normalized path is the base directory itself or lives underneath it.
Used by producers to keep a caller-supplied file name from escaping the endpoint directory.
public static bool IsWithinDirectory(string basePath, string candidatePath, char separator, StringComparison comparison)
Remarks
The separator is part of the comparison on purpose: a plain prefix test would accept
"/data/out2/x" as living inside "/data/out".