continue parsing after nested call
authorMarco Rossignoli <marco.rossignoli@gmail.com>
Fri, 1 Mar 2019 22:11:29 +0000 (23:11 +0100)
committerMarco Rossignoli <marco.rossignoli@gmail.com>
Fri, 1 Mar 2019 22:11:29 +0000 (23:11 +0100)
Commit migrated from https://github.com/dotnet/corefx/commit/b2865f5e4dcda0a3745b96d704aebec82ab22d60

src/libraries/System.Net.Http/src/System/Net/Http/HttpRuleParser.cs
src/libraries/System.Net.Http/tests/UnitTests/HttpRuleParserTest.cs

index d718be1..2570797 100644 (file)
@@ -431,9 +431,12 @@ namespace System.Net.Http
                     {
                         nestedCount--;
                     }
+
+                    // after nested call we continue with parsing
+                    continue;
                 }
 
-                if (current < input.Length &&  input[current] == closeChar)
+                if (input[current] == closeChar)
                 {
                     length = current - startIndex + 1;
                     return HttpParseResult.Parsed;
index 3c49017..9326184 100644 (file)
@@ -241,6 +241,8 @@ namespace System.Net.Http.Tests
             AssertGetCommentLength("((\\)))", 0, 6, HttpParseResult.Parsed); // ((\))) -> quoted-pair )
             AssertGetCommentLength("((\\())", 0, 6, HttpParseResult.Parsed); // ((\()) -> quoted-pair (
             AssertGetCommentLength("((x)))", 0, 5, HttpParseResult.Parsed); // final ) ignored
+            AssertGetCommentLength("(x (y)(z))", 0, 10, HttpParseResult.Parsed);
+            AssertGetCommentLength("(x(y)\\()", 0, 8, HttpParseResult.Parsed);
         }
 
         [Fact]
@@ -257,6 +259,12 @@ namespace System.Net.Http.Tests
             // of nested comments. I.e. the following comment is considered invalid since it is considered a 
             // "malicious" comment.
             AssertGetCommentLength("((((((((((x))))))))))", 0, 0, HttpParseResult.InvalidFormat);
+            AssertGetCommentLength("(x(x)", 0, 0, HttpParseResult.InvalidFormat);
+            AssertGetCommentLength("(x(x(", 0, 0, HttpParseResult.InvalidFormat);
+            AssertGetCommentLength("(x(()", 0, 0, HttpParseResult.InvalidFormat);
+            AssertGetCommentLength("(()", 0, 0, HttpParseResult.InvalidFormat);
+            AssertGetCommentLength("(", 0, 0, HttpParseResult.InvalidFormat);
+            AssertGetCommentLength("((x)", 0, 0, HttpParseResult.InvalidFormat);
         }
 
         [Fact]