Modified format logic so that braces are not allowed in custom format specifiers...
authorMike Marynowski <mikernet@users.noreply.github.com>
Wed, 22 May 2019 02:58:49 +0000 (22:58 -0400)
committerJeremy Kuhne <jeremy.kuhne@microsoft.com>
Wed, 22 May 2019 02:58:49 +0000 (19:58 -0700)
* Modified format logic so that braces are not allowed in custom format specifiers.

* Disabled failing test temporarily and fixed code style issue.

PR needed to pass test: https://github.com/dotnet/corefx/pull/35820

* Slight changes to logic to better align the diff.

* Fixed counting error.

* Fix nullable

* Move exclusion near related test

* Add skip to new issue file

* Delete CoreFX.issues.json

Commit migrated from https://github.com/dotnet/coreclr/commit/5d8fea006d98d98ba269056de519199f354bcf1a

src/coreclr/tests/CoreFX/CoreFX.issues.rsp
src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs

index 28b1ed7..8d48a84 100644 (file)
 -nomethod System.Numerics.Tests.Vector4Tests.Vector4ClampTest
 -noclass System.Diagnostics.Tests.DebugTests
 -nomethod System.Text.Tests.StringBuilderTests.Equals
+-nomethod System.Text.Tests.StringBuilderTests.AppendFormat
 -nomethod System.Tests.DecimalTests.Remainder
 -nomethod System.Tests.DecimalTests.Remainder_Invalid
 -nomethod System.Tests.DecimalTests+BigIntegerMod.Test
index 38d5945..ec9d2c4 100644 (file)
@@ -1538,7 +1538,6 @@ namespace System.Text
             int pos = 0;
             int len = format.Length;
             char ch = '\x0';
-            StringBuilder? unescapedItemFormat = null;
 
             ICustomFormatter? cf = null;
             if (provider != null)
@@ -1665,7 +1664,7 @@ namespace System.Text
                 // Start of parsing of optional formatting parameter.
                 //
                 object? arg = args[index];
-                string? itemFormat = null;
+
                 ReadOnlySpan<char> itemFormatSpan = default; // used if itemFormat is null
                 // Is current character a colon? which indicates start of formatting parameter.
                 if (ch == ':')
@@ -1678,67 +1677,40 @@ namespace System.Text
                         // If reached end of text then error. (Unexpected end of text)
                         if (pos == len) FormatError();
                         ch = format[pos];
-                        pos++;
 
-                        // Is character a opening or closing brace?
-                        if (ch == '}' || ch == '{')
+                        if (ch == '}')
                         {
-                            if (ch == '{')
-                            {
-                                // Yes, is next character also a opening brace, then treat as escaped. eg {{
-                                if (pos < len && format[pos] == '{')
-                                    pos++;
-                                else
-                                    // Error Argument Holes can not be nested.
-                                    FormatError();
-                            }
-                            else
-                            {
-                                // Yes, is next character also a closing brace, then treat as escaped. eg }}
-                                if (pos < len && format[pos] == '}')
-                                    pos++;
-                                else
-                                {
-                                    // No, then treat it as the closing brace of an Arg Hole.
-                                    pos--;
-                                    break;
-                                }
-                            }
-
-                            // Reaching here means the brace has been escaped
-                            // so we need to build up the format string in segments
-                            if (unescapedItemFormat == null)
-                            {
-                                unescapedItemFormat = new StringBuilder();
-                            }
-                            unescapedItemFormat.Append(format, startPos, pos - startPos - 1);
-                            startPos = pos;
+                            // Argument hole closed
+                            break;
                         }
-                    }
-
-                    if (unescapedItemFormat == null || unescapedItemFormat.Length == 0)
-                    {
-                        if (startPos != pos)
+                        else if (ch == '{')
                         {
-                            // There was no brace escaping, extract the item format as a single string
-                            itemFormatSpan = format.AsSpan(startPos, pos - startPos);
+                            // Braces inside the argument hole are not supported
+                            FormatError();
                         }
+
+                        pos++;
                     }
-                    else
+
+                    if (pos > startPos)
                     {
-                        unescapedItemFormat.Append(format, startPos, pos - startPos);
-                        itemFormatSpan = itemFormat = unescapedItemFormat.ToString();
-                        unescapedItemFormat.Clear();
+                        itemFormatSpan = format.AsSpan(startPos, pos - startPos);
                     }
                 }
-                // If current character is not a closing brace then error. (Unexpected Character)
-                if (ch != '}') FormatError();
+                else if (ch != '}')
+                {
+                    // Unexpected character
+                    FormatError();
+                }
+
                 // Construct the output for this arg hole.
                 pos++;
                 string? s = null;
+                string? itemFormat = null;
+                
                 if (cf != null)
                 {
-                    if (itemFormatSpan.Length != 0 && itemFormat == null)
+                    if (itemFormatSpan.Length != 0)
                     {
                         itemFormat = new string(itemFormatSpan);
                     }