fix(research): avoid double split() call and potential IndexError (#2229)
cat.split()[0] was called in the condition and again in the body, wasting a second split. More importantly, if cat were ever whitespace-only, split() returns [] and [0] raises IndexError. Assign to a local variable and guard with a truthiness check. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
706ea6a7b7
commit
b9a96bca1a
1 changed files with 2 additions and 1 deletions
|
|
@ -439,7 +439,8 @@ class DeepResearcher:
|
||||||
)
|
)
|
||||||
cat = (result or "").strip().lower()
|
cat = (result or "").strip().lower()
|
||||||
# Clean one-word answer first.
|
# Clean one-word answer first.
|
||||||
first = cat.split()[0].strip(".,\"'*:") if cat.split() else ""
|
parts = cat.split()
|
||||||
|
first = parts[0].strip(".,\"'*:") if parts else ""
|
||||||
if first in CATEGORY_PROMPTS:
|
if first in CATEGORY_PROMPTS:
|
||||||
return first
|
return first
|
||||||
# Weak local models often wrap the label in preamble ("the category
|
# Weak local models often wrap the label in preamble ("the category
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue