TryAddWithoutValidation ViaHeaderValue (#72741)
authorfeiyun0112 <feiyun0112@gmail.com>
Mon, 25 Jul 2022 15:24:41 +0000 (23:24 +0800)
committerGitHub <noreply@github.com>
Mon, 25 Jul 2022 15:24:41 +0000 (08:24 -0700)
* TryAddWithoutValidation ViaHeaderValue

* checking for 0

src/libraries/System.Net.Http/src/System/Net/Http/Headers/ViaHeaderValue.cs
src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeadersTest.cs

index 98012da..5903655 100644 (file)
@@ -169,7 +169,7 @@ namespace System.Net.Http.Headers
 
             // If we reached the end of the string after reading protocolName/Version we return (we expect at least
             // <receivedBy> to follow). If reading protocolName/Version read 0 bytes, we return.
-            if ((current == startIndex) || (current == input.Length))
+            if ((current == 0) || (current == input.Length))
             {
                 return 0;
             }
index 6f8947e..4fbff52 100644 (file)
@@ -71,6 +71,16 @@ namespace System.Net.Http.Tests
             Assert.Equal(expectedValues, headers.NonValidated["Accept"]);
         }
 
+        [Fact]
+        public void TryAddWithoutValidation_AddInvalidViaHeaderValue_ValuePassed()
+        {
+            MockHeaders headers = new MockHeaders();
+            headers.TryAddWithoutValidation("Via", "1.1 foo.bar, foo");
+
+            Assert.Equal(1, headers.First().Value.Count());
+            Assert.Equal("1.1 foo.bar, foo", headers.First().Value.ElementAt(0));
+        }
+
         [Theory]
         [InlineData(null)]
         [InlineData("")]