Skip to content

Fix type guards throwing on null or undefined in protocol package - #1940

Open
Siddharth S (codeXsidd) wants to merge 2 commits into
microsoft:mainfrom
codeXsidd:fix/issue-1939-text-document-filter-typeguards
Open

Siddharth S (codeXsidd) wants to merge 2 commits into
microsoft:mainfrom
codeXsidd:fix/issue-1939-text-document-filter-typeguards

Conversation

@codeXsidd

Copy link
Copy Markdown

Summary

Ensures TextDocumentFilter.is, TextDocumentRegistrationOptions.is, WorkDoneProgressOptions.hasWorkDoneProgress, and DiagnosticServerCancellationData.is safely handle null and undefined without throwing TypeError and return boolean results.

Problem

TextDocumentFilter.is did not verify whether a non-string candidate is an object literal before reading candidate properties (candidate.language). Passing null or undefined threw TypeError: Cannot read properties of null (reading 'language') instead of returning false.

Consequently, composite guards like DocumentSelector.is([null]) and TextDocumentRegistrationOptions.is({ documentSelector: [null] }) crashed with a TypeError. In addition, TextDocumentRegistrationOptions.is(null), WorkDoneProgressOptions.hasWorkDoneProgress(null), and DiagnosticServerCancellationData.is(null) returned null rather than boolean false.

Solution

  • Added Is.objectLiteral(candidate) checks in TextDocumentFilter.is, TextDocumentRegistrationOptions.is, WorkDoneProgressOptions.hasWorkDoneProgress, and DiagnosticServerCancellationData.is.
  • Added unit tests in protocol/src/node/test/documentFilter.test.ts covering TextDocumentFilter.is, DocumentSelector.is, TextDocumentRegistrationOptions.is, WorkDoneProgressOptions.hasWorkDoneProgress, and DiagnosticServerCancellationData.is for valid filters, relative patterns, invalid values, and null / undefined.

Testing

  • npm run compile:protocol: passed cleanly
  • npm run compile (full project build mode across all packages): passed cleanly
  • npm --prefix protocol run lint: passed cleanly (0 errors)
  • npm --prefix protocol run test:node: passed (all 26 tests passing)
  • npm --prefix types test: passed (all 58 tests passing)
  • npm --prefix server test: passed (all 17 tests passing)

Related Issue

Closes #1939

Copilot AI balanced review requested due to automatic review settings October 31, 2026 16:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@codeXsidd

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the null-safe protocol type-guard changes.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 1, 2026 17:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the null-safe protocol type guard changes.

No open issues 🎉

Review effort: Balanced

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.

TextDocumentFilter.is throws TypeError when called with null or undefined

2 participants