Skip to content

[BUG]: Incorrect Indexing in handle_plural_values() Causes Inconsistent Whitespace Formatting #96

@krrishrastogi05

Description

@krrishrastogi05

🐛 Bug Report

About: Create a report to help us improve FireForm. Title: [BUG]: Off-by-one error in handle_plural_values() Labels: bug


⚡️ Describe the Bug

The handle_plural_values() method in src/llm.py contains an off-by-one indexing issue when removing whitespace from plural values.

The loop modifies values[i + 1] instead of values[i], which causes the first element in the list to be skipped during whitespace cleanup. This results in inconsistent formatting when plural values are returned by the LLM.


👣 Steps to Reproduce

  1. Call handle_plural_values() with input:

    "value1 ; value2 ; value3"
    
  2. Inspect the returned list.

  3. Observe that the first element may retain trailing whitespace.


📉 Expected Behavior

All elements obtained after splitting the string by ";" should have both leading and trailing whitespace removed consistently.

Example expected output:

["value1", "value2", "value3"]

🖥️ Environment Information

Field Details
OS Any
Docker/Compose Version N/A
Ollama Model Used Mistral

📸 Screenshots / Logs

Problematic implementation:

values = plural_value.split(";")

for i in range(len(values)):
current = i + 1
if current < len(values):
clean_value = values[current].lstrip()
values[current] = clean_value

Issues:

  • Skips index 0
  • Requires boundary checking due to i + 1
  • Uses lstrip() instead of strip()
  • Introduces unnecessary indexing complexity

🕵️ Possible Fix

Replace the loop with a safer and cleaner implementation:

values = [v.strip() for v in plural_value.split(";")]

This fix:

  • Cleans all elements
  • Removes both leading and trailing whitespace
  • Eliminates off-by-one indexing
  • Simplifies the logic

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions