-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[App Config] az appconfig kv set/import: Add support for JSON comments
#32130
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
Merged
zhoxing-ms
merged 17 commits into
Azure:dev
from
albertofori:albertofori/strip_comments
Sep 29, 2025
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f4386ac
Fix MSI auth.
albertofori 8d5f9c5
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
albertofori 453940c
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
albertofori fee7024
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
albertofori 39505ed
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
albertofori 9c5b0a6
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
albertofori 13e8693
Merge branch 'dev' of https://github.com/Azure/azure-cli into alberto…
albertofori 8cc3fdb
Add handling of comments in json file.
albertofori b07dde5
Merge branch 'dev' of https://github.com/Azure/azure-cli into alberto…
albertofori eb78251
Addressing comments.
albertofori cc4d5f5
Addressing comments
albertofori 96398da
Updating string and escaping.
albertofori b893441
Linting
albertofori 019b46b
Addressing comments.
albertofori 39121ce
Remove comment support for specialized config.
albertofori 8e04be7
Fix linting issues.
albertofori 3cea7a6
Adding license to new file.
albertofori File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,13 @@ | |
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
| DOUBLE_QUOTE = '\"' | ||
| BACKSLASH = '\\' | ||
| DOUBLE_SLASH = '//' | ||
| MULTILINE_COMMENT_START = '/*' | ||
| MULTILINE_COMMENT_END = '*/' | ||
| NEW_LINE = '\n' | ||
|
|
||
|
|
||
| def construct_connection_string(cmd, config_store_name): | ||
| connection_string_template = 'Endpoint={};Id={};Secret={}' | ||
|
|
@@ -254,3 +261,73 @@ def parse_tags_to_dict(tags): | |
| tags_dict[tag_key] = tag_value | ||
| return tags_dict | ||
| return tags | ||
|
|
||
|
|
||
|
albertofori marked this conversation as resolved.
Outdated
|
||
| def strip_json_comments(json_string): | ||
|
albertofori marked this conversation as resolved.
Outdated
|
||
| current_index = 0 | ||
| length = len(json_string) | ||
| result = [] | ||
|
|
||
| def __isEscaped(json_string, char_index): | ||
| backslash_count = 0 | ||
| idx = char_index - 1 | ||
| while idx >= 0 and json_string[idx] == '\\': | ||
|
albertofori marked this conversation as resolved.
Outdated
|
||
| backslash_count += 1 | ||
| idx -= 1 | ||
|
|
||
| return backslash_count % 2 == 1 | ||
|
|
||
| def __find_next_newline_index(json_string, start_index): | ||
|
albertofori marked this conversation as resolved.
Outdated
|
||
| idx = start_index | ||
|
|
||
| while idx < length: | ||
| if json_string[idx] == NEW_LINE: | ||
| break | ||
|
albertofori marked this conversation as resolved.
Outdated
|
||
|
|
||
| idx += 1 | ||
|
|
||
| return idx | ||
|
|
||
| def __find_next_double_quote_index(json_string, start_index): | ||
|
albertofori marked this conversation as resolved.
Outdated
|
||
| idx = start_index | ||
| while idx < length: | ||
| if json_string[idx] == DOUBLE_QUOTE and not __isEscaped(json_string, idx): | ||
| return idx | ||
|
|
||
| idx += 1 | ||
|
|
||
| raise ValueError("Unterminated string literal") | ||
|
|
||
| def __find_next_multiline_comment_end(json_string, start_index): | ||
|
albertofori marked this conversation as resolved.
Outdated
|
||
| idx = start_index | ||
| while idx < length - 1: | ||
| if json_string[idx:idx + 2] == MULTILINE_COMMENT_END: | ||
| return idx + 1 | ||
|
|
||
| idx += 1 | ||
|
|
||
| raise ValueError("Unterminated multi-line comment") | ||
|
albertofori marked this conversation as resolved.
Outdated
|
||
|
|
||
| while current_index < length: | ||
| # Single line comment | ||
| if json_string[current_index:current_index + 2] == DOUBLE_SLASH: | ||
| current_index = __find_next_newline_index(json_string, current_index) | ||
| if current_index < length and json_string[current_index] == NEW_LINE: | ||
| result.append(NEW_LINE) | ||
|
|
||
| # Multi-line comment | ||
| elif json_string[current_index:current_index + 2] == MULTILINE_COMMENT_START: | ||
| current_index = __find_next_multiline_comment_end(json_string, current_index + 2) | ||
|
|
||
| # String literal | ||
| elif json_string[current_index] == DOUBLE_QUOTE: | ||
| literal_start_index = current_index | ||
| current_index = __find_next_double_quote_index(json_string, current_index + 1) | ||
|
|
||
| result.extend(json_string[literal_start_index:current_index + 1]) | ||
| else: | ||
| result.append(json_string[current_index]) | ||
|
|
||
| current_index += 1 | ||
|
|
||
| return "".join(result) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.