-
Notifications
You must be signed in to change notification settings - Fork 2
Implement JSON output cleaning for Azure CLI commands #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Added a method to clean JSON output from Azure CLI commands to remove control characters and non-JSON content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds JSON output sanitization to Azure CLI command processing to handle cases where Azure CLI returns control characters or non-JSON content in its output. The implementation introduces a new CleanJsonOutput helper method that removes control characters and strips any text before the first JSON bracket.
Key changes:
- Added
CleanJsonOutputmethod to remove control characters (0x00-0x1F) and locate JSON start markers - Integrated cleaning logic into four Azure CLI methods:
GetCurrentAccountAsync,ListResourceGroupsAsync,ListAppServicePlansAsync, andListLocationsAsync - Added null/empty output validation after cleaning in all affected methods
src/Microsoft.Agents.A365.DevTools.Cli/Services/AzureCliService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/AzureCliService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/AzureCliService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/AzureCliService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/AzureCliService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/AzureCliService.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/AzureCliService.cs
Outdated
Show resolved
Hide resolved
Added JSON output cleaning functionality to improve parsing of Azure CLI responses.
…aning - Added CleanAzureCliJsonOutput method to JsonDeserializationHelper - Updated AzureCliService, AzureAuthValidator, and BotConfigurator to use the shared helper - Removed duplicate CleanJsonOutput methods from individual services - Fixes JSON parsing errors when Azure CLI outputs control characters (0x0C) on Windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
src/Microsoft.Agents.A365.DevTools.Cli/Services/Helpers/JsonDeserializationHelper.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Helpers/JsonDeserializationHelper.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Helpers/JsonDeserializationHelper.cs
Show resolved
Hide resolved
…rom main - Added tenantId parameter back to GetAccessTokenAsync calls - Restored comprehensive error handling for delete endpoint failures - Re-added Microsoft.Agents.A365.DevTools.Cli.Exceptions using statement - Maintains JSON cleaning functionality while aligning with main branch changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
src/Microsoft.Agents.A365.DevTools.Cli/Services/Helpers/JsonDeserializationHelper.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/Helpers/JsonDeserializationHelper.cs
Show resolved
Hide resolved
| // Remove control characters (0x00-0x1F except \r, \n, \t) | ||
| // These characters can appear in Azure CLI output on Windows | ||
| var cleaned = new System.Text.StringBuilder(output.Length); | ||
| foreach (char c in output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know what is different with your tenant?
When would we get control characters?
In preview001 or ztaitest12 or testcsaa where we have been testing so far, we didn't see this. Wondering if this can have a negative impact for those tenants/users.
How do we ensure that?
Added a method to clean JSON output from Azure CLI commands to remove control characters and non-JSON content.
The Problem
The error was caused by invalid control characters (specifically 0x0C - form feed character) in the Azure CLI output. When the tool ran az account show --output json, the output contained non-JSON characters that prevented successful JSON deserialization.