Repository navigation
fix(autocomplete): referenceText must not emit invalid MQL for unsafe field names - #713
Conversation
… field names
Previously, toFieldCompletionItems() always emitted referenceText as
\`\$\${entry.path}\`, which produces invalid MQL for field names such as
"order-items", "my field", or "say\"hi\"" (e.g., \`\$order-items\`).
Fix: check each dot-separated path segment individually against
JS_IDENTIFIER_PATTERN.
- All segments valid → \`\$field.path\` (existing behaviour, e.g., \`\$address.city\`)
- Flat field with unsafe name → \`{ \$getField: "name" }\`
- Nested path with an unsafe segment → referenceText omitted (chained
\$getField form is complex; tracked as a follow-up in future-work.md)
FieldCompletionData.referenceText widened from required \`string\` to
optional \`string | undefined\` (\`referenceText?: string\`) so that tRPC
type inference on the client side stays consistent.
Closes microsoft#709
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Thank you for this contribution, and apologies for the delay in responding. With the larger volume of PRs coming in recently, we missed this submission and started reviewing another PR that addresses the same issue (#717). That was an oversight on our side, not a reflection of the quality of your work here. Your PR was actually the earlier submission, it was clean and isolated, and importantly it avoided emitting invalid MQL by returning an undefined reference for the nested unsafe case rather than producing a wrong expression. While finalizing #717 we added a few improvements on top of the shared approach:
Because #717 builds out those additional cases, we are going to merge #717 to close out #709. This is not a quality judgment against your PR, the two overlapped and we are consolidating on one. We appreciate the time and care you put into this, and we hope to see more contributions from you. Closing this in favor of #717, with thanks. |
Summary
Closes #709
toFieldCompletionItems()previously emittedreferenceTextas`$${entry.path}`for every field, which produces invalid MQL for field names containing special characters (e.g.,$order-items,$my field).Changes:
JS_IDENTIFIER_PATTERNindividually (not the full path, so nested paths likeaddress.citykeep their valid$address.cityform)order-items) →{ $getField: "order-items" }order.item-count) →referenceTextomitted; chained$getFieldform is complex and tracked as a follow-up infuture-work.mdFieldCompletionData.referenceTextwidened fromstringtostring?so the tRPC client-side inferred type stays consistentfuture-work.mditem 2 marked as resolvedBehaviour table
age$age✅$age✅address.city$address.city✅$address.city✅order-items$order-items❌{ $getField: "order-items" }✅my field$my field❌{ $getField: "my field" }✅say"hi"$say"hi"❌{ $getField: "say\"hi\"" }✅order.item-count$order.item-count❌undefined✅ (no invalid MQL emitted)Test plan
toFieldCompletionItems.test.ts— 13 tests pass (3 new tests added for unsafe flat fields, unsafe nested paths, and safe nested paths)tsc --noEmit— no type errors🤖 Generated with Claude Code