fix(translate): answer a request whose texts are all empty with 200 as well

Every text is answered now, blank or not, so the all-empty case needs no
rule of its own: "" and [""] are texts with nothing to translate in them,
and they are answered with themselves like any other blank text. A missing
or null `text` decodes to the one empty string and is answered the same
way.

The 404 is left for a request that names no text at all: `"text": []`, the
one shape there is nothing to answer with. Nothing else errors on
emptiness.

Refs #244.
This commit is contained in:
JounQin
2026-10-10 23:39:45 +08:00
parent 7269cf615a
commit 4fb2759d48
4 changed files with 60 additions and 65 deletions
+1 -4
View File
@@ -104,10 +104,7 @@ func TestTranslateByDLXRejectsOversizedTextsBeforeUpstream(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, length, ok := textsToTranslate(tt.texts)
if !ok {
t.Fatalf("textsToTranslate(%q) reported no text", tt.texts)
}
_, length := textsToTranslate(tt.texts)
if length <= maxFreeTextLength {
t.Fatalf("textsToTranslate(%q) = %d, which is not over the limit", tt.texts, length)
}