Commit 9466ecb
committed
Add explicit handling for collection Contains filters in LINQ expressions
Enhance GoogleTextSearch LINQ filter processing to explicitly detect and reject collection Contains operations (e.g., array.Contains(page.Property)) with a clear, actionable error message.
Changes:
- Added IsMemoryExtensionsContains helper method to detect C# 14+ span-based Contains resolution
- Enhanced TryProcessSingleExpression to distinguish between:
* String.Contains (supported for substring search)
* Enumerable.Contains / MemoryExtensions.Contains (not supported - now explicitly rejected)
- Throws NotSupportedException with guidance on alternatives when collection Contains is detected
- Handles both C# 13- (Enumerable.Contains) and C# 14+ (MemoryExtensions.Contains) resolution paths
Test Coverage:
- Added CollectionContainsFilterThrowsNotSupportedExceptionAsync test
- Verifies exception is thrown for collection Contains operations
- Validates error message contains actionable guidance about OR logic limitations
- Ensures consistent behavior across C# language versions (13 vs 14 Contains resolution)
Rationale:
Google Custom Search API does not support OR logic across multiple values. Collection Contains filters would require OR semantics that cannot be expressed via Google's query parameters. This change provides clear, early feedback to developers attempting to use unsupported filter patterns.
Related to reviewer feedback on LINQ expression filter validation and C# 14 compatibility. Fixes #104561 parent 8f333d2 commit 9466ecb
File tree
2 files changed
+69
-5
lines changed- dotnet/src/Plugins
- Plugins.UnitTests/Web/Google
- Plugins.Web/Google
2 files changed
+69
-5
lines changedLines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
700 | 700 | | |
701 | 701 | | |
702 | 702 | | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
703 | 732 | | |
704 | 733 | | |
705 | 734 | | |
| |||
Lines changed: 40 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
| 225 | + | |
| 226 | + | |
229 | 227 | | |
230 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
231 | 250 | | |
232 | 251 | | |
233 | 252 | | |
| |||
239 | 258 | | |
240 | 259 | | |
241 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
242 | 277 | | |
243 | 278 | | |
244 | 279 | | |
| |||
0 commit comments