Repository: microsoft/PowerToys
File: src/modules/registrypreview/RegistryPreviewUI/MainWindow.Utilities.cs (C#)

Code before:
                        registryLine = ScanAndRemoveComments(registryLine);
                        registryLine = registryLine.TrimStart();
                        value += registryLine;
                    }

                    // Clean out any escaped characters in the value, only for the preview
                    value = StripEscapedCharacters(value);

                    // update the ListViewItem with the loaded value, based off REG value type
                    switch (registryValue.Type)
                    {
                        case "ERROR":
                            // do nothing
                            break;
                        case "REG_BINARY":
                        case "REG_NONE":
                            if (value.Length <= 0)
                            {
                                value = resourceLoader.GetString("ZeroLength");
                            }
                            else
                            {
                                try
                                {
                                    // Hexes are usually two characters (00), it's invalid if less or more than 2
                                    var bytes = value.Split(',').Select(
                                        c => c.Length == 2 ? byte.Parse(c, NumberStyles.HexNumber, CultureInfo.InvariantCulture) : throw null);
                                    value = string.Join(' ', bytes.Select(b => b.ToString("x2", CultureInfo.CurrentCulture)));
                                }
                                catch
                                {
                                    value = resourceLoader.GetString("InvalidBinary");
                                }
                            }

                            registryValue.Value = value;

                            break;
                        case "REG_DWORD":
                            if (value.Length <= 0)
                            {
                                value = resourceLoader.GetString("InvalidDword");
                            }
                            else
                            {
                                if (uint.TryParse(value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint dword))
                                {
                                    value = $"0x{dword:x8} ({dword})";
                                }
                                else
                                {

Review comment (suggestion):
This should still be in the code, for an error case.  I was explicitly asked to show an error icon for invalid values.  Without it, icon will not show in the list view.  I understand it will not make the Previewer look exactly like the Editor, but that's kind of the point, when actively editing a REG file: the Editor will simply drop values on the floor (or pop up a message box) whereas the Preview is more of a sandbox to fix errors, if need be.

Code after:
                        registryLine = ScanAndRemoveComments(registryLine);
                        registryLine = registryLine.TrimStart();
                        value += registryLine;
                    }

                    // update the ListViewItem with the loaded value, based off REG value type
                    switch (registryValue.Type)
                    {
                        case "ERROR":
                            // do nothing
                            break;
                        case "REG_SZ":
                            if (value == "\"")
                            {
                                // Value is most likely missing an end quote
                                registryValue.Type = "ERROR";
                                value = resourceLoader.GetString("InvalidString");
                            }
                            else
                            {
                                for (int i = 1; i < value.Length; i++)
                                {
                                    if (value[i - 1] == '\\')
                                    {
                                        // Only allow these escape characters
                                        if (value[i] != '"' && value[i] != '\\')
                                        {
                                            registryValue.Type = "ERROR";
                                            value = resourceLoader.GetString("InvalidString");
                                            break;
                                        }

                                        i++;
                                    }

                                    if (value[i - 1] != '\\' && value[i] == '"')
                                    {
                                        // Don't allow non-escaped quotes
                                        registryValue.Type = "ERROR";
                                        value = resourceLoader.GetString("InvalidString");
                                        break;
                                    }
                                }

                                if (registryValue.Type != "ERROR")
                                {
                                    // Clean out any escaped characters in the value, only for the preview
                                    value = StripEscapedCharacters(value);
                                }
                            }