From 63ebe2c946d8952924c9665032d441b0599b5bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Sat, 9 Nov 2024 17:51:04 +0100 Subject: [PATCH] Fixed improper caase conversion of strings leading to encoding bugs (#71) --- src/PnP/Devcon.cs | 10 +++++----- src/PnP/PnPDevice.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PnP/Devcon.cs b/src/PnP/Devcon.cs index 941ee24..95700b4 100644 --- a/src/PnP/Devcon.cs +++ b/src/PnP/Devcon.cs @@ -100,7 +100,7 @@ public static unsafe bool FindInDeviceClassByHardwareId(Guid target, string hard throw new ConfigManagerException("Failed to get device ID.", ret); } - string instanceId = new string(ptrInstanceBuf).ToUpper(); + string instanceId = new string(ptrInstanceBuf).ToUpperInvariant(); PnPDevice device = PnPDevice.GetDeviceByInstanceId( instanceId, @@ -116,11 +116,11 @@ public static unsafe bool FindInDeviceClassByHardwareId(Guid target, string hard continue; } - List hardwareIds = property.Select(id => id.ToUpper()).ToList(); + List hardwareIds = property.Select(id => id.ToUpperInvariant()).ToList(); if ( /* partial match */ - (allowPartial && hardwareIds.Any(id => id.Contains(hardwareId.ToUpper()))) || + (allowPartial && hardwareIds.Any(id => id.Contains(hardwareId.ToUpperInvariant()))) || /* exact match */ (!allowPartial && hardwareIds.Contains(hardwareId, StringComparer.OrdinalIgnoreCase)) ) @@ -198,7 +198,7 @@ ref da { IntPtr pDevicePathName = detailDataBuffer + 4; - path = (Marshal.PtrToStringAuto(pDevicePathName) ?? string.Empty).ToUpper(); + path = (Marshal.PtrToStringAuto(pDevicePathName) ?? string.Empty).ToUpperInvariant(); if (memberIndex == instance) { @@ -214,7 +214,7 @@ ref da char* ptrInstanceBuf = stackalloc char[(int)nBytes]; PInvoke.CM_Get_Device_IDW(da.DevInst, ptrInstanceBuf, nBytes, 0); - instanceId = new string(ptrInstanceBuf).ToUpper(); + instanceId = new string(ptrInstanceBuf).ToUpperInvariant(); return true; } diff --git a/src/PnP/PnPDevice.cs b/src/PnP/PnPDevice.cs index 1a8165c..25f7cf4 100644 --- a/src/PnP/PnPDevice.cs +++ b/src/PnP/PnPDevice.cs @@ -189,7 +189,7 @@ public unsafe void Remove() /// @"Nefarius\VirtualPad" // VirtualPad /// }; /// - /// return hardwareIds.Any(id => excludedIds.Contains(id.ToUpper())); + /// return hardwareIds.Any(id => excludedIds.Contains(id.ToUpperInvariant())); /// }); /// public bool IsVirtual(Func? excludeIfMatches = default)