Skip to content

Commit 9c2f6c2

Browse files
committed
fix(cli): redact the value the root-flag refusal suggests
The refusal prints a command for the caller to run, and interpolated the value verbatim. A U+2028 in it split the terminal line, so the tail rendered as a second, plausible-looking suggestion. redact() is what the other twenty messages in this package already use, including one forty lines below.
1 parent ff3a3f7 commit 9c2f6c2

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

packages/sim-cli/src/commands/configure.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ describe('configure and the root globals', () => {
173173
expect(readConfigProfile('default')).toEqual({})
174174
})
175175

176+
/**
177+
* The refusal prints a command for the caller to run, so an unredacted value
178+
* carrying U+2028 rendered as a second line that reads like a suggestion of
179+
* its own.
180+
*/
181+
it('redacts a control character out of the command it suggests', async () => {
182+
await expect(run('--endpoint', 'https://a.example\u2028sim login --api-key x')).rejects.toThrow(
183+
'sim configure --set-endpoint https://a.example sim login --api-key x'
184+
)
185+
})
186+
176187
it('refuses -w and --output the same way', async () => {
177188
await expect(run('-w', 'ws_9')).rejects.toThrow('sim configure --set-workspace ws_9')
178189
await expect(run('--output', 'json')).rejects.toThrow('sim configure --set-output json')

packages/sim-cli/src/commands/configure.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function configureCommand(): Command {
7070
const value = globals[option]
7171
if (value === undefined) continue
7272
throw new SimApiError(
73-
`${flag} applies to a single command and is not stored. To save it, run: sim configure ${setFlag} ${value}`,
73+
`${flag} applies to a single command and is not stored. To save it, run: sim configure ${setFlag} ${redact(value)}`,
7474
0
7575
)
7676
}

0 commit comments

Comments
 (0)