Skip to content

Commit ddab42d

Browse files
committed
fix(subtitles): drop dead async-replace path (duplicate API calls); stripped text on every output path (CodeQL)
1 parent 6fbdac9 commit ddab42d

1 file changed

Lines changed: 2 additions & 22 deletions

File tree

src/components/SubtitlesProcessor.vue

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,6 @@ async function run() {
4848
let count = 0
4949
5050
try {
51-
const out = inputText.value.replace(CUE_RE, async (_match, idx, time, dialogue: string) => {
52-
// Strip HTML formatting tags before transliterating
53-
const stripped = dialogue.replace(/<[^>]*>/g, "").replace(/[<>]/g, "").trim()
54-
// eslint-disable-next-line no-control-regex -- \x00-\x7F is the full ASCII range
55-
if (!/[^\x00-\x7F]/.test(stripped)) {
56-
return `${idx ?? ""}${time}\n${dialogue}`.trim()
57-
}
58-
try {
59-
const transliterated = await client!.transliterate(system.value, stripped)
60-
count++
61-
return `${idx ?? ""}${time}\n${transliterated}`
62-
} catch {
63-
return `${idx ?? ""}${time}\n${dialogue}`
64-
}
65-
})
66-
67-
// Because String.replace doesn't await async replacers, redo with
68-
// sequential await.
6951
const cues: { idx: string; time: string; dialogue: string }[] = []
7052
let m: RegExpExecArray | null
7153
const re = new RegExp(CUE_RE.source, "g")
@@ -76,7 +58,6 @@ async function run() {
7658
dialogue: m[3]!,
7759
})
7860
}
79-
8061
if (cues.length === 0) {
8162
output.value = inputText.value
8263
cueCount.value = 0
@@ -89,20 +70,19 @@ async function run() {
8970
const stripped = cue.dialogue.replace(/<[^>]*>/g, "").replace(/[<>]/g, "").trim()
9071
// eslint-disable-next-line no-control-regex -- \x00-\x7F is the full ASCII range
9172
if (!/[^\x00-\x7F]/.test(stripped)) {
92-
outParts.push(`${cue.idx}${cue.time}\n${cue.dialogue}`.trim())
73+
outParts.push(`${cue.idx}${cue.time}\n${stripped}`)
9374
continue
9475
}
9576
try {
9677
const transliterated = await client.transliterate(system.value, stripped)
9778
count++
9879
outParts.push(`${cue.idx}${cue.time}\n${transliterated}`)
9980
} catch {
100-
outParts.push(`${cue.idx}${cue.time}\n${cue.dialogue}`)
81+
outParts.push(`${cue.idx}${cue.time}\n${stripped}`)
10182
}
10283
}
10384
output.value = outParts.join("\n\n")
10485
cueCount.value = count
105-
void out
10686
} catch (e) {
10787
error.value = (e as Error).message
10888
}

0 commit comments

Comments
 (0)