Remove UNC path check from System.Drawing.Icon.ExtractAssociatedIcon (dotnet/corefx...
authorMarco Rossignoli <marco.rossignoli@gmail.com>
Thu, 10 Jan 2019 19:13:18 +0000 (20:13 +0100)
committerDan Moseley <danmose@microsoft.com>
Thu, 10 Jan 2019 19:13:18 +0000 (11:13 -0800)
* remove UNC check

* add ActiveIssue to test

* address PR feedback

* address PR feedback

Commit migrated from https://github.com/dotnet/corefx/commit/fd999b17c19a6f6cef0eb6be8c2df5bdb3f863e7

src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.cs
src/libraries/System.Drawing.Common/tests/IconTests.cs

index 4ebb26e..3a396ae 100644 (file)
@@ -178,11 +178,6 @@ namespace System.Drawing
                 uri = new Uri(filePath);
             }
 
-            if (uri.IsUnc)
-            {
-                throw new ArgumentException(SR.Format(SR.InvalidArgumentValue, nameof(filePath), filePath));
-            }
-
             if (!uri.IsFile)
             {
                 return null;
index 64f4965..3bed03b 100644 (file)
@@ -385,7 +385,37 @@ namespace System.Drawing.Tests
         [ConditionalFact(Helpers.IsDrawingSupported)]
         public void ExtractAssociatedIcon_FilePath_Success()
         {
-            using (Icon icon = Icon.ExtractAssociatedIcon(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico")))
+            ExtractAssociatedIcon_FilePath_Success(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
+        }
+
+        [PlatformSpecific(TestPlatforms.Windows)] // UNC
+        [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Fix for #34122")]
+        [ConditionalFact(Helpers.IsDrawingSupported)]
+        public void ExtractAssociatedIcon_UNCFilePath_Success()
+        {
+            string bitmapPath = Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico");
+            string bitmapPathRoot = Path.GetPathRoot(bitmapPath);
+            string bitmapUncPath = $"\\\\{Environment.MachineName}\\{bitmapPath.Substring(0, bitmapPathRoot.IndexOf(":"))}$\\{bitmapPath.Replace(bitmapPathRoot, "")}";
+
+            // Some path could not be accessible
+            // if so we just pass the test
+            try
+            {
+                File.Open(bitmapUncPath, FileMode.Open, FileAccess.Read, FileShare.Read).Dispose();
+            }
+            catch(IOException)
+            {
+                return;
+            }
+
+            Assert.True(new Uri(bitmapUncPath).IsUnc);
+
+            ExtractAssociatedIcon_FilePath_Success(bitmapUncPath);
+        }
+
+        private void ExtractAssociatedIcon_FilePath_Success(string filePath)
+        {
+            using (Icon icon = Icon.ExtractAssociatedIcon(filePath))
             {
                 Assert.Equal(32, icon.Width);
                 Assert.Equal(32, icon.Height);
@@ -405,13 +435,10 @@ namespace System.Drawing.Tests
             AssertExtensions.Throws<ArgumentNullException, ArgumentException>("filePath", null, () => Icon.ExtractAssociatedIcon(null));
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
-        [ConditionalTheory(Helpers.IsDrawingSupported)]
-        [InlineData("", "path")]
-        [InlineData("\\\\uncpath", null)]
-        public void ExtractAssociatedIcon_InvalidFilePath_ThrowsArgumentException(string filePath, string paramName)
+        [ConditionalFact(Helpers.IsDrawingSupported)]
+        public void ExtractAssociatedIcon_InvalidFilePath_ThrowsArgumentException()
         {
-            AssertExtensions.Throws<ArgumentException>(paramName, null, () => Icon.ExtractAssociatedIcon(filePath));
+            AssertExtensions.Throws<ArgumentException>("path", null, () => Icon.ExtractAssociatedIcon(""));
         }