Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when the Segment Terminator is a '\n' character #99

Open
arenius opened this issue Jan 15, 2020 · 0 comments
Open

Errors when the Segment Terminator is a '\n' character #99

arenius opened this issue Jan 15, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@arenius
Copy link

arenius commented Jan 15, 2020

  • badX12 version: '0.2.2'
  • Python version: Python 3.6.8
  • Operating System: Ubuntu

Description

I'm trying to parse an incoming X12 (834) document. The error is an IndexError but the actual issue seems to be that this file is using a newline character as the segment terminator but newlines are stripped in the "_validate_document" method that is run prior to the parsing step.

There seems to be some discussion on weather or not newline characters are valid segment terminators: kputnam/stupidedi#106

I've gotten things working for me by changing the return statement of the _validate_document method from "return document.replace("\n", "").strip()" to "return document" but I'm not sure if that will change things for other use cases.

What I Did

I have a small test script to start understanding how to use the library:

from badx12 import Parser
parser = Parser()
document = parser.parse_document("test_file.834")
  File "t.py", line 4, in <module>
    document = parser.parse_document("test_file.834")
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 37, in parse_document
    self._separate_and_route_segments()
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 101, in _separate_and_route_segments
    self._route_segment_to_parser(segment)
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 114, in _route_segment_to_parser
    self._parse_transaction_set_header(segment)
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 193, in _parse_transaction_set_header
    self._parse_segment(transaction_header, header_field_list)
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 134, in _parse_segment
    raise e
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 129, in _parse_segment
    segment.fields[index].content = value
IndexError: list index out of range
@albmarin albmarin added the bug Something isn't working label Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants