Skip to content

Commit f155a70

Browse files
committed
Fixes header parsing based upon the earliest index
1 parent ac2fa5c commit f155a70

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/https/Program.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,24 +359,38 @@ class Content
359359

360360
public static bool TryParse(string s, out Content content)
361361
{
362-
var index = s.IndexOf('=');
362+
var equalsIndex = s.IndexOf('=');
363+
var colonIndex = s.IndexOf(':');
364+
if (equalsIndex == -1 && colonIndex == -1)
365+
{
366+
content = default;
367+
return false;
368+
}
369+
363370
var contentType = default(ContentLocation);
364-
if (index == -1)
371+
var index = default(int);
372+
if (equalsIndex > -1 && colonIndex > -1)
365373
{
366-
index = s.IndexOf(':');
367-
if (index == -1)
374+
if (equalsIndex < colonIndex)
368375
{
369-
content = default;
370-
return false;
376+
contentType = ContentLocation.Body;
377+
index = equalsIndex;
371378
}
372379
else
373380
{
374381
contentType = ContentLocation.Header;
382+
index = colonIndex;
375383
}
376384
}
377-
else
385+
else if (equalsIndex > -1)
378386
{
379387
contentType = ContentLocation.Body;
388+
index = equalsIndex;
389+
}
390+
else
391+
{
392+
contentType = ContentLocation.Header;
393+
index = colonIndex;
380394
}
381395

382396
var property = s.Substring(0, index);

0 commit comments

Comments
 (0)