Redact the normalized CLI key and keep a WebVTT cue that follows the header directly

Review fixes for #4558 and #4554.
This commit is contained in:
debpalash committed 2026-11-30 20:08:51 +05:30
1 parent 2d7f3a4f89
commit eaa28c9b37
4 files changed
+30 -2

No files matched your search

+5 -2
View File
@@ -13,8 +13,11 @@ class CLIError(Exception):
def scrub(value: str, secrets=()) -> str:
for secret in secrets:
if secret:
value = value.replace(secret, '[redacted]')
# Requests send the normalized credential (BOM and whitespace dropped),
# so redact that form too, whatever form the caller registered.
for form in (secret, (secret or '').removeprefix('\ufeff').strip()):
if form:
value = value.replace(form, '[redacted]')
value = re.sub(r'(?i)(bearer\s+)[^\s"<>]+', r'\1[redacted]', value)
value = re.sub(r'(https?://)[^/\s@]+@', r'\1[redacted]@', value)
value = re.sub(r'(?i)((?:api_key|token|password|pin)=)[^&\s]+', r'\1[redacted]', value)
+13
View File
@@ -114,9 +114,22 @@ function spokenCueText(text, webvtt = false) {
return spoken.replace(/[^\S\n]+/g, ' ').trim();
}
/** Split a file header that runs straight into its first cue (no blank line). */
function splitHeaderCue(block) {
const lines = block.split('\n').filter((l) => l.trim());
if (!/^WEBVTT(?:[ \t]|$)/.test(lines[0]?.trim() || '')) return [block];
const timed = (i) => isTimingLine((lines[i] || '').trim());
if (timed(1)) return [block];
for (let i = 1; i < lines.length; i += 1) {
if (timed(i) || timed(i + 1)) return [lines.slice(0, i).join('\n'), lines.slice(i).join('\n')];
}
return [block];
}
function captionBlocks(text, webvtt) {
const blocks = text.split(/\n\s*\n/);
if (!webvtt) return blocks;
if (blocks.length) blocks.splice(0, 1, ...splitHeaderCue(blocks[0]));
return blocks.filter((b) => {
const lines = b
.split('\n')
@@ -150,6 +150,14 @@ describe('parseSrt', () => {
}
expect(parseSrt('WEBVTT\n00:00:01.000 --> 00:00:02.000\nHello\n')).toBe('Hello');
});
it('keeps the first cue when the header runs into it without a blank line', () => {
for (const header of ['WEBVTT', 'WEBVTT\nKind: captions', 'WEBVTT\nKind: captions\nLanguage: en']) {
const vtt =
`${header}\nWEBVTT intro\n00:00:01.000 --> 00:00:02.000\nFirst cue\n\n` +
'00:00:02.000 --> 00:00:03.000\nSecond cue\n';
expect(parseSrt(vtt)).toBe('First cue\nSecond cue');
}
});
it('still drops a WebVTT header that carries metadata and no cue timing', () => {
for (const header of ['WEBVTT', 'WEBVTT Kind: captions', 'WEBVTT\tKind: captions']) {
const vtt = `${header}\nLanguage: en\n\n00:00:01.000 --> 00:00:02.000\nHello\n`;
+4
View File
@@ -164,6 +164,10 @@ class IsolationTests(unittest.TestCase):
self.assertNotIn('abc', output); self.assertNotIn('secret', output)
self.assertNotIn('u:p', output); self.assertNotIn('\x1b', output)
def test_redaction_covers_the_normalized_bom_key(self):
output = scrub('backend echoed key-123 in its error', ['key-123\n'])
self.assertNotIn('key-123', output)
def test_parser_failures_are_structured(self):
for args in [['speak'], ['engines', 'list', '--type', 'wrong'],
['status', '--timeout', 'NaN'], ['status', '--timeout', '-1'],