Skip to content

Commit c929f35

Browse files
committed
refactor(sources): scan the Link header with an explicit index instead of mutating the for-loop variable
1 parent 00cbcb5 commit c929f35

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/Sources/NeoReports.Sources.Http/HttpBatchSource.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,17 @@ private static IEnumerable<string> SplitLinkValues(string headerValue)
170170
var inAngle = false;
171171
var inQuotes = false;
172172

173-
for (var i = 0; i < headerValue.Length; i++)
173+
var i = 0;
174+
while (i < headerValue.Length)
174175
{
175176
char c = headerValue[i];
176177

177-
// A backslash escape is only meaningful inside a quoted-string (RFC 9110 quoted-pair);
178-
// skipping the next char there keeps an escaped quote from ending the string early.
178+
// Inside a quoted string a backslash escapes whatever follows it, so both characters are
179+
// stepped over together — otherwise an escaped quote would look like the end of the
180+
// string and every delimiter after it would be read in the wrong state.
179181
if (inQuotes && c == '\\')
180182
{
181-
i++;
183+
i += 2;
182184
continue;
183185
}
184186

@@ -193,6 +195,8 @@ private static IEnumerable<string> SplitLinkValues(string headerValue)
193195
yield return headerValue[start..i];
194196
start = i + 1;
195197
}
198+
199+
i++;
196200
}
197201

198202
yield return headerValue[start..];

0 commit comments

Comments
 (0)