[debug-certificate-manager] Fix home directory parsing for shells that echo commands
Summary
When resolving the home directory in remote environments, shells that echo executed commands (e.g., set -x) cause output containing multiple instances of the marker strings. The parser was extracting from the first occurrence instead of the actual command output.
Details
Changed marker parsing from indexOf() to lastIndexOf() to extract from the final occurrence:
// Before: Extracts from first marker pair (echoed command text)
const startIndex: number = output.indexOf(markerPrefix);
const endIndex: number = output.indexOf(markerSuffix);
// After: Extracts from last marker pair (actual output)
const startIndex: number = output.lastIndexOf(markerPrefix);
const endIndex: number = output.lastIndexOf(markerSuffix);
if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {
Added validation that end marker follows start marker to handle malformed output.
Bumped the package version from 0.0.6 to 0.0.7 as version bumping for VSCode extensions is not automatic.
How it was tested
Created test scripts simulating shell echo scenarios:
- Verified
indexOf()incorrectly extracts command text when shell echoes - Verified
lastIndexOf()correctly extracts home directory with echo enabled - Verified backward compatibility with shells that don't echo
- Validated edge cases: unbalanced markers, multiple pairs
Impacted documentation
None.
Original prompt
In the debug certificate manager VSCode Extension, when looking for the home directory, some shells echo the command being executed before executing it. The output processor should therefore look for the last instance of the markers, rather than the first.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
@copilot Also make a patch bump to the affected vscode extension package version, since version bumping of vscode extensions is not automatic.
@copilot Also make a patch bump to the affected vscode extension package version, since version bumping of vscode extensions is not automatic.
Done. Bumped version from 0.0.6 to 0.0.7 in commit 7cd82c0.