Skip to content

FIX: Runtime crash in textToJSON.add_response_to_json #183

Open
Aryama-srivastav wants to merge 3 commits intofireform-core:mainfrom
Aryama-srivastav:182
Open

FIX: Runtime crash in textToJSON.add_response_to_json #183
Aryama-srivastav wants to merge 3 commits intofireform-core:mainfrom
Aryama-srivastav:182

Conversation

@Aryama-srivastav
Copy link

Description

This PR fixes a runtime crash in textToJSON.add_response_to_json when the same field is processed more than once.

Previously, the first value for a field was stored as a scalar, but on repeated occurrences the code attempted to call .append(...) on that scalar, raising:
AttributeError: 'str' object has no attribute 'append'.

This change makes duplicate-field handling type-safe:

  • if field appears once → keep scalar behavior
  • if field appears again → convert stored scalar to list and append new value
  • if already list → append normally

Fixes #182

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Test A (duplicate field path):

    • Ran:
      python -c "import sys; sys.path.insert(0,'src'); from backend import textToJSON; obj=textToJSON.new(textToJSON); obj._textToJSON__json={}; obj.add_response_to_json('Employee name','John'); obj.add_response_to_json('Employee name','Jane'); print(obj._textToJSON__json)"
    • Verified output:
      {'Employee name': ['John', 'Jane']}
      Verified no crash.
  • Test B (single field behavior):

    • Ran:
      python -c "import sys; sys.path.insert(0,'src'); from backend import textToJSON; obj=textToJSON.new(textToJSON); obj._textToJSON__json={}; obj.add_response_to_json('Department','Operations'); print(obj._textToJSON__json)"
    • Verified output:
      {'Department': 'Operations'}

Test Configuration:

  • Firmware version: N/A
  • Hardware: Local development machine (Windows)
  • SDK: N/A
  • Python: 3.13
  • Shell: PowerShell

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG : textToJSON.add_response_to_json() crashes when the same field is processed more than once.

1 participant