Remove file system/security/util/URLString.cs
authorRahul Kumar <rahku@microsoft.com>
Sat, 1 Apr 2017 00:11:24 +0000 (17:11 -0700)
committerRahul Kumar <rahku@microsoft.com>
Wed, 5 Apr 2017 02:45:57 +0000 (19:45 -0700)
src/mscorlib/System.Private.CoreLib.csproj
src/mscorlib/src/System/AppDomainSetup.cs
src/mscorlib/src/System/Security/Util/URLString.cs [deleted file]

index 6f18a4f..8121daf 100644 (file)
     <Compile Include="$(BclSourcesRoot)\System\Security\VerificationException.cs" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="$(BclSourcesRoot)\System\Security\Util\URLString.cs" />
-  </ItemGroup>
-  <ItemGroup>
     <Compile Include="$(BclSourcesRoot)\System\Diagnostics\Assert.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Diagnostics\AssertFilter.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Diagnostics\AssertFilters.cs" />
index 2529660..907ac69 100644 (file)
@@ -52,7 +52,6 @@ namespace System
 
         // Constants from fusionsetup.h.
         private const string LOADER_OPTIMIZATION = "LOADER_OPTIMIZATION";
-        private const string CONFIGURATION_EXTENSION = ".config";
 
         private const string ACTAG_APP_BASE_URL = "APPBASE";
 
@@ -131,7 +130,7 @@ namespace System
                 else
                     _AppDomainInitializer = null;
 
-                _ConfigurationBytes = copy.GetConfigurationBytes();
+                _ConfigurationBytes = null; 
 #if FEATURE_COMINTEROP
                 _DisableInterfaceCache = copy._DisableInterfaceCache;
 #endif // FEATURE_COMINTEROP
@@ -178,7 +177,6 @@ namespace System
                 else
                     ApplicationBase = appBase;
             }
-            ConfigurationFile = ApplicationName + AppDomainSetup.ConfigurationExtension;
         }
 
         internal string[] Value
@@ -191,11 +189,6 @@ namespace System
             }
         }
 
-        internal String GetUnsecureApplicationBase()
-        {
-            return Value[(int)LoaderInformation.ApplicationBaseValue];
-        }
-
         public string AppDomainManagerAssembly
         {
             get { return _AppDomainManagerAssembly; }
@@ -213,246 +206,15 @@ namespace System
             [Pure]
             get
             {
-                return VerifyDir(GetUnsecureApplicationBase(), false);
+                return Value[(int)LoaderInformation.ApplicationBaseValue];
             }
 
             set
             {
-                Value[(int)LoaderInformation.ApplicationBaseValue] = NormalizePath(value, false);
+                Value[(int)LoaderInformation.ApplicationBaseValue] = (value == null || value.Length == 0)?null:Path.GetFullPath(value);
             }
         }
-
-        private String NormalizePath(String path, bool useAppBase)
-        {
-            if (path == null)
-                return null;
-
-            // If we add very long file name support ("\\?\") to the Path class then this is unnecesary,
-            // but we do not plan on doing this for now.
-
-            // Long path checks can be quirked, and as loading default quirks too early in the setup of an AppDomain is risky
-            // we'll avoid checking path lengths- we'll still fail at MAX_PATH later if we're !useAppBase when we call Path's
-            // NormalizePath.
-            if (!useAppBase)
-                path = Security.Util.URLString.PreProcessForExtendedPathRemoval(
-                    checkPathLength: false,
-                    url: path,
-                    isFileUrl: false);
-
-
-            int len = path.Length;
-            if (len == 0)
-                return null;
-
-#if !PLATFORM_UNIX
-            bool UNCpath = false;
-#endif // !PLATFORM_UNIX
-
-            if ((len > 7) &&
-                (String.Compare(path, 0, "file:", 0, 5, StringComparison.OrdinalIgnoreCase) == 0))
-            {
-                int trim;
-
-                if (path[6] == '\\')
-                {
-                    if ((path[7] == '\\') || (path[7] == '/'))
-                    {
-                        // Don't allow "file:\\\\", because we can't tell the difference
-                        // with it for "file:\\" + "\\server" and "file:\\\" + "\localpath"
-                        if ((len > 8) &&
-                             ((path[8] == '\\') || (path[8] == '/')))
-                            throw new ArgumentException(SR.Argument_InvalidPathChars);
-
-                        // file:\\\ means local path
-                        else
-#if !PLATFORM_UNIX
-                            trim = 8;
-#else
-                            // For Unix platform, trim the first 7 characters only.
-                            // Trimming the first 8 characters will cause
-                            // the root path separator to be trimmed away,
-                            // and the absolute local path becomes a relative local path.
-                            trim = 7;
-#endif // !PLATFORM_UNIX
-                    }
-
-                    // file:\\ means remote server
-                    else
-                    {
-                        trim = 5;
-#if !PLATFORM_UNIX
-                        UNCpath = true;
-#endif // !PLATFORM_UNIX
-                    }
-                }
-
-                // local path
-                else if (path[7] == '/')
-#if !PLATFORM_UNIX
-                    trim = 8;
-#else
-                    // For Unix platform, trim the first 7 characters only.
-                    // Trimming the first 8 characters will cause
-                    // the root path separator to be trimmed away,
-                    // and the absolute local path becomes a relative local path.
-                    trim = 7;
-#endif // !PLATFORM_UNIX
-
-                // remote
-                else
-                {
-                    // file://\\remote
-                    if ((len > 8) && (path[7] == '\\') && (path[8] == '\\'))
-                        trim = 7;
-                    else
-                    { // file://remote
-                        trim = 5;
-#if !PLATFORM_UNIX
-                        // Create valid UNC path by changing
-                        // all occurences of '/' to '\\' in path
-                        System.Text.StringBuilder winPathBuilder =
-                            new System.Text.StringBuilder(len);
-                        for (int i = 0; i < len; i++)
-                        {
-                            char c = path[i];
-                            if (c == '/')
-                                winPathBuilder.Append('\\');
-                            else
-                                winPathBuilder.Append(c);
-                        }
-                        path = winPathBuilder.ToString();
-#endif // !PLATFORM_UNIX
-                    }
-#if !PLATFORM_UNIX
-                    UNCpath = true;
-#endif // !PLATFORM_UNIX
-                }
-
-                path = path.Substring(trim);
-                len -= trim;
-            }
-
-#if !PLATFORM_UNIX
-            bool localPath;
-
-            // UNC
-            if (UNCpath ||
-                ((len > 1) &&
-                  ((path[0] == '/') || (path[0] == '\\')) &&
-                  ((path[1] == '/') || (path[1] == '\\'))))
-                localPath = false;
-
-            else
-            {
-                int colon = path.IndexOf(':') + 1;
-
-                // protocol other than file:
-                if ((colon != 0) &&
-                    (len > colon + 1) &&
-                    ((path[colon] == '/') || (path[colon] == '\\')) &&
-                    ((path[colon + 1] == '/') || (path[colon + 1] == '\\')))
-                    localPath = false;
-
-                else
-                    localPath = true;
-            }
-
-            if (localPath)
-#else
-            if ( (len == 1) ||
-                 ( (path[0] != '/') && (path[0] != '\\') ) ) 
-#endif // !PLATFORM_UNIX
-            {
-                if (useAppBase &&
-                    ((len == 1) || (path[1] != ':')))
-                {
-                    String appBase = Value[(int)LoaderInformation.ApplicationBaseValue];
-
-                    if ((appBase == null) || (appBase.Length == 0))
-                        throw new MemberAccessException(SR.AppDomain_AppBaseNotSet);
-
-                    StringBuilder result = StringBuilderCache.Acquire();
-
-                    bool slash = false;
-                    if ((path[0] == '/') || (path[0] == '\\'))
-                    {
-                        string pathRoot = AppDomain.NormalizePath(appBase, fullCheck: false);
-                        pathRoot = pathRoot.Substring(0, IO.PathInternal.GetRootLength(pathRoot));
-
-                        if (pathRoot.Length == 0)
-                        { // URL
-                            int index = appBase.IndexOf(":/", StringComparison.Ordinal);
-                            if (index == -1)
-                                index = appBase.IndexOf(":\\", StringComparison.Ordinal);
-
-                            // Get past last slashes of "url:http://"
-                            int urlLen = appBase.Length;
-                            for (index += 1;
-                                 (index < urlLen) && ((appBase[index] == '/') || (appBase[index] == '\\'));
-                                 index++) ;
-
-                            // Now find the next slash to get domain name
-                            for (; (index < urlLen) && (appBase[index] != '/') && (appBase[index] != '\\');
-                                index++) ;
-
-                            pathRoot = appBase.Substring(0, index);
-                        }
-
-                        result.Append(pathRoot);
-                        slash = true;
-                    }
-                    else
-                        result.Append(appBase);
-
-                    // Make sure there's a slash separator (and only one)
-                    int aLen = result.Length - 1;
-                    if ((result[aLen] != '/') &&
-                        (result[aLen] != '\\'))
-                    {
-                        if (!slash)
-                        {
-#if !PLATFORM_UNIX
-                            if (appBase.IndexOf(":/", StringComparison.Ordinal) == -1)
-                                result.Append('\\');
-                            else
-#endif // !PLATFORM_UNIX
-                                result.Append('/');
-                        }
-                    }
-                    else if (slash)
-                        result.Remove(aLen, 1);
-
-                    result.Append(path);
-                    path = StringBuilderCache.GetStringAndRelease(result);
-                }
-                else
-                    path = AppDomain.NormalizePath(path, fullCheck: true);
-            }
-
-            return path;
-        }
-
-        public String ConfigurationFile
-        {
-            get
-            {
-                return VerifyDir(Value[(int)LoaderInformation.ConfigurationFileValue], true);
-            }
-
-            set
-            {
-                Value[(int)LoaderInformation.ConfigurationFileValue] = value;
-            }
-        }
-
-        public byte[] GetConfigurationBytes()
-        {
-            if (_ConfigurationBytes == null)
-                return null;
-
-            return (byte[])_ConfigurationBytes.Clone();
-        }
-
+        
         // only needed by AppDomain.Setup(). Not really needed by users. 
         internal Dictionary<string, object> GetCompatibilityFlags()
         {
@@ -497,22 +259,6 @@ namespace System
             }
         }
 
-        private String VerifyDir(String dir, bool normalize)
-        {
-            if (dir != null)
-            {
-                if (dir.Length == 0)
-                    dir = null;
-                else
-                {
-                    if (normalize)
-                        dir = NormalizePath(dir, true);
-                }
-            }
-
-            return dir;
-        }
-
         public String ApplicationName
         {
             get
@@ -594,14 +340,6 @@ namespace System
             }
         }
 
-        internal static string ConfigurationExtension
-        {
-            get
-            {
-                return CONFIGURATION_EXTENSION;
-            }
-        }
-
         static internal int Locate(String s)
         {
             if (String.IsNullOrEmpty(s))
diff --git a/src/mscorlib/src/System/Security/Util/URLString.cs b/src/mscorlib/src/System/Security/Util/URLString.cs
deleted file mode 100644 (file)
index 33aac6f..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-//  URLString
-//
-//
-//  Implementation of membership condition for zones
-//
-
-namespace System.Security.Util
-{
-    using System;
-    using System.Collections;
-    using System.Collections.Generic;
-    using System.Runtime.CompilerServices;
-    using System.Runtime.InteropServices;
-    using System.Runtime.Versioning;
-    using System.Runtime.Serialization;
-    using System.Globalization;
-    using System.Text;
-    using System.IO;
-    using System.Diagnostics.Contracts;
-
-    internal static class URLString
-    {
-        internal static string PreProcessForExtendedPathRemoval(bool checkPathLength, string url, bool isFileUrl)
-        {
-            bool isUncShare = false;
-            return PreProcessForExtendedPathRemoval(checkPathLength: checkPathLength, url: url, isFileUrl: isFileUrl, isUncShare: ref isUncShare);
-        }
-
-        // Keeping this signature to avoid reflection breaks
-        private static string PreProcessForExtendedPathRemoval(string url, bool isFileUrl, ref bool isUncShare)
-        {
-            return PreProcessForExtendedPathRemoval(checkPathLength: true, url: url, isFileUrl: isFileUrl, isUncShare: ref isUncShare);
-        }
-
-        private static string PreProcessForExtendedPathRemoval(bool checkPathLength, string url, bool isFileUrl, ref bool isUncShare)
-        {
-            // This is the modified URL that we will return
-            StringBuilder modifiedUrl = new StringBuilder(url);
-
-            // ITEM 1 - remove extended path characters.
-            {
-                // Keep track of where we are in both the comparison and altered strings.
-                int curCmpIdx = 0;
-                int curModIdx = 0;
-
-                // If all the '\' have already been converted to '/', just check for //?/ or //./
-                if ((url.Length - curCmpIdx) >= 4 &&
-                    (String.Compare(url, curCmpIdx, "//?/", 0, 4, StringComparison.OrdinalIgnoreCase) == 0 ||
-                     String.Compare(url, curCmpIdx, "//./", 0, 4, StringComparison.OrdinalIgnoreCase) == 0))
-                {
-                    modifiedUrl.Remove(curModIdx, 4);
-                    curCmpIdx += 4;
-                }
-                else
-                {
-                    if (isFileUrl)
-                    {
-                        // We need to handle an indefinite number of leading front slashes for file URLs since we could
-                        // get something like:
-                        //      file://\\?\
-                        //      file:/\\?\
-                        //      file:\\?\
-                        //      etc...
-                        while (url[curCmpIdx] == '/')
-                        {
-                            curCmpIdx++;
-                            curModIdx++;
-                        }
-                    }
-
-                    // Remove the extended path characters
-                    if ((url.Length - curCmpIdx) >= 4 &&
-                        (String.Compare(url, curCmpIdx, "\\\\?\\", 0, 4, StringComparison.OrdinalIgnoreCase) == 0 ||
-                         String.Compare(url, curCmpIdx, "\\\\?/", 0, 4, StringComparison.OrdinalIgnoreCase) == 0 ||
-                         String.Compare(url, curCmpIdx, "\\\\.\\", 0, 4, StringComparison.OrdinalIgnoreCase) == 0 ||
-                         String.Compare(url, curCmpIdx, "\\\\./", 0, 4, StringComparison.OrdinalIgnoreCase) == 0))
-                    {
-                        modifiedUrl.Remove(curModIdx, 4);
-                        curCmpIdx += 4;
-                    }
-                }
-            }
-
-            // ITEM 2 - convert all slashes to forward slashes, and strip leading slashes.
-            if (isFileUrl)
-            {
-                int slashCount = 0;
-                bool seenFirstBackslash = false;
-
-                while (slashCount < modifiedUrl.Length && (modifiedUrl[slashCount] == '/' || modifiedUrl[slashCount] == '\\'))
-                {
-                    // Look for sets of consecutive backslashes. We can't just look for these at the start
-                    // of the string, since file:// might come first.  Instead, once we see the first \, look
-                    // for a second one following it.
-                    if (!seenFirstBackslash && modifiedUrl[slashCount] == '\\')
-                    {
-                        seenFirstBackslash = true;
-                        if (slashCount + 1 < modifiedUrl.Length && modifiedUrl[slashCount + 1] == '\\')
-                            isUncShare = true;
-                    }
-
-                    slashCount++;
-                }
-
-                modifiedUrl.Remove(0, slashCount);
-                modifiedUrl.Replace('\\', '/');
-            }
-
-            // ITEM 3 - If the path is greater than or equal (due to terminating NULL in windows) MAX_PATH, we throw.
-            if (checkPathLength)
-            {
-                // This needs to be a separate method to avoid hitting the static constructor on AppContextSwitches
-                CheckPathTooLong(modifiedUrl);
-            }
-
-            // Create the result string from the StringBuilder
-            return modifiedUrl.ToString();
-        }
-
-        [MethodImpl(MethodImplOptions.NoInlining)]
-        private static void CheckPathTooLong(StringBuilder path)
-        {
-            if (path.Length >= (
-#if PLATFORM_UNIX
-                Interop.Sys.MaxPath))
-#else
-                PathInternal.MaxLongPath))
-#endif
-            {
-                throw new PathTooLongException(SR.IO_PathTooLong);
-            }
-        }
-    }
-}