Ejemplo n.º 1
0
        private static void CheckIllegalCharacters(String[] str, bool onlyCheckExtras)
        {
#if !PLATFORM_UNIX
            for (int i = 0; i < str.Length; ++i)
            {
                // FileIOPermission doesn't allow for normalizing across various volume names. This means "C:\" and
                // "\\?\C:\" won't be considered correctly. In addition there are many other aliases for the volume
                // besides "C:" such as (in one concrete example) "\\?\Harddisk0Partition2\", "\\?\HarddiskVolume6\",
                // "\\?\Volume{d1655348-0000-0000-0000-f01500000000}\", etc.
                //
                // We'll continue to explicitly block extended syntax here by disallowing wildcards no matter where
                // they occur in the string (e.g. \\?\ isn't ok)
                if (CheckExtraPathCharacters(str[i]))
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPathChars"));
                }

                if (!onlyCheckExtras)
                {
                    PathInternal.CheckInvalidPathChars(str[i]);
                }
            }
#else
            // There are no "extras" on Unix
            if (onlyCheckExtras)
            {
                return;
            }

            for (int i = 0; i < str.Length; ++i)
            {
                PathInternal.CheckInvalidPathChars(str[i]);
            }
#endif
        }
Ejemplo n.º 2
0
        /// <summary>
        /// To get the file name of a ZipArchiveEntry, we should be parsing the FullName based
        /// on the path specifications and requirements of the OS that ZipArchive was created on.
        /// This method takes in a FullName and the platform of the ZipArchiveEntry and returns
        /// the platform-correct file name.
        /// </summary>
        internal static string ParseFileName(string path, ZipVersionMadeByPlatform madeByPlatform)
        {
            // Validation checking is done based on current OS, not source OS.
            PathInternal.CheckInvalidPathChars(path);

            if (madeByPlatform == ZipVersionMadeByPlatform.Unix)
            {
                int length = path.Length;
                for (int i = length; --i >= 0;)
                {
                    if (path[i] == '/')
                    {
                        return(path.Substring(i + 1));
                    }
                }
                return(path);
            }
            else
            {
                return(Path.GetFileName(path));
            }
        }
Ejemplo n.º 3
0
 public void CheckInvalidPathChars_ThrowsOnNull()
 {
     Assert.Throws <ArgumentNullException>(() => PathInternal.CheckInvalidPathChars(null));
 }