Skip to content

Commit

Permalink
Merge pull request #448 from microsoftgraph/bugfixes/$SearchValues
Browse files Browse the repository at this point in the history
Format Search Values
  • Loading branch information
peombwa authored Nov 2, 2020
2 parents f757249 + ecd79e1 commit 8225941
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/readme.graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ directive:
// Call OnBeforeWriteObject to deserialize '@odata.count' from the response object.
let writeObjectRegex = /^(\s*)(WriteObject\(result\.Value,true\);)$/gm
$ = $.replace(writeObjectRegex,'\n$1OnBeforeWriteObject(this.InvocationInformation.BoundParameters, result?.AdditionalProperties);\n$1$2');
// Format all Search values by adding quotes around them.
let searchQueryRegex = /this\.InvocationInformation\.BoundParameters\.ContainsKey\("Search"\)\s*\?\s*Search\s*:\s*null/gm
$ = $.replace(searchQueryRegex, 'this.FormatSearchValue(this.InvocationInformation.BoundParameters, Search)');
}
return $;
}
Expand Down
21 changes: 21 additions & 0 deletions tools/Custom/ListCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ public bool ShouldIteratePages(global::System.Collections.Generic.Dictionary<str
return nextLinkUri.Uri;
}

/// <summary>
/// Adds quotation mark around $search values if none exists.
/// This is needed to support KQL e.g. "prop:value".
/// </summary>
/// <param name="boundParameters">The bound parameters of the calling cmdlet.</param>
/// <param name="search">The $search value.</param>
/// <returns>A formated search value.</returns>
internal string FormatSearchValue(global::System.Collections.Generic.Dictionary<string, object> boundParameters, string search)
{
if (!boundParameters.ContainsKey("Search"))
{
return null;
}
else if (!string.IsNullOrWhiteSpace(search) && !search.StartsWith("\""))
{
search = $"\"{search}\"";
}

return search;
}

internal void OnBeforeWriteObject(global::System.Collections.Generic.Dictionary<string, object> boundParameters, global::System.Collections.Generic.IDictionary<string, object> additionalProperties)
{
// Get odata.count from the response.
Expand Down

0 comments on commit 8225941

Please sign in to comment.