Skip to content

Fix IndexOutOfRangeException in VSTestBridge BuildFilter UID escaping by @azat-msft in #9771 (backport to rel/4.3) - #10112

Merged
Amaury Levé (Evangelink) merged 5 commits into
microsoft:rel/4.3from
nohwnd-bot:backport/9771/to/rel/4.3
Jul 21, 2026
Merged

Amaury Levé (Evangelink) merged 5 commits into
microsoft:rel/4.3from
nohwnd-bot:backport/9771/to/rel/4.3

Conversation

@nohwnd-bot

Copy link
Copy Markdown
Contributor

ContextAdapterBase.BuildFilter reconstructs a VSTest TestCaseFilter from a
TestNodeUidListFilter (the by-UID selection IDEs send over the server protocol).
Its hand-rolled escaper guarded the "is this char already escaped?" check with the
node index (i) instead of the character index (k): it read
currentTestNodeUid.Value[k - 1] while testing i - 1 < 0. For any node after the
first (i > 0) whose first character (k == 0) is a filter operator, this evaluated
Value[-1] and threw IndexOutOfRangeException, aborting the whole run. The same
index confusion could also under-escape an operator that follows a literal
backslash.

Replace the loop with VSTest's canonical FilterHelper.Escape, which escapes every
filter operator ('\ ( ) & | = ! ~') unconditionally -- exactly what a raw
test-node UID needs -- removing the index bug.

Add RunContextAdapterFilterTests covering BuildFilter output: FullyQualifiedName
vs Id=<guid> selection, multi-node OR joining, runsettings/command-line filters,
operator escaping, and the two regressions above (a later node starting with an
operator no longer throws; backslash-then-operator escapes both characters).

Co-authored-by: Copilot <[email protected]>
Assert the built filter not only produces the expected escaped string but also
actually matches (via ITestCaseFilterExpression.MatchTestCase) a test case whose
FullyQualifiedName is exactly the escaped name and rejects others, guarding the
full escape -> parse -> match path against a future parser-side regression.

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
TestNodeUid lives in Microsoft.Testing.Platform.Extensions.Messages; that using
was removed as 'unused' but CreateUidFilter constructs TestNodeUid, so all TFMs
failed to compile with CS0246. Re-add the directive in alphabetical order.

Co-authored-by: Copilot App <[email protected]>
@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) July 21, 2026 13:04
@Evangelink
Amaury Levé (Evangelink) merged commit 4fb1a03 into microsoft:rel/4.3 Jul 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants