if (path.Length == 0)
throw new ArgumentException(SR.Arg_PathEmpty, nameof(path));
+ if (path.IndexOf('\0') != -1)
+ throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path));
+
// Expand with current directory if necessary
if (!IsPathRooted(path))
{
internal const string ParentDirectoryPrefix = @"../";
- /// <summary>Returns a value indicating if the given path contains invalid characters.</summary>
- internal static bool HasIllegalCharacters(string path)
- {
- Debug.Assert(path != null);
- return path.IndexOf(InvalidPathChar) >= 0;
- }
-
internal static int GetRootLength(string path)
{
return path.Length > 0 && IsDirectorySeparator(path[0]) ? 1 : 0;
}
/// <summary>
- /// Returns a value indicating if the given path contains invalid characters (", <, >, |
- /// NUL, or any ASCII char whose integer representation is in the range of 1 through 31).
- /// Does not check for wild card characters ? and *.
- /// </summary>
- internal static bool HasIllegalCharacters(string path)
- {
- // This is equivalent to IndexOfAny(InvalidPathChars) >= 0,
- // except faster since IndexOfAny grows slower as the input
- // array grows larger.
- // Since we know that some of the characters we're looking
- // for are contiguous in the alphabet-- the path cannot contain
- // characters 0-31-- we can optimize this for our specific use
- // case and use simple comparison operations.
-
- for (int i = 0; i < path.Length; i++)
- {
- char c = path[i];
- if (c <= '|') // fast path for common case - '|' is highest illegal character
- {
- if (c <= '\u001f' || c == '|')
- {
- return true;
- }
- }
- }
-
- return false;
- }
-
- /// <summary>
/// Check for known wildcard characters. '*' and '?' are the most common ones.
/// </summary>
internal static bool HasWildCardCharacters(string path)