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

String index out of range when converting a line #17

Closed
ShaneSutro opened this issue Jun 17, 2021 · 0 comments · Fixed by #18
Closed

String index out of range when converting a line #17

ShaneSutro opened this issue Jun 17, 2021 · 0 comments · Fixed by #18
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@ShaneSutro
Copy link
Owner

Describe the bug
When converting a line with vestaboard.Formatter().convertLine() that contains text and bracket-encoded characters exactly the length of the line (22 characters), conversion fails with the message IndexError: string index out of range.

To Reproduce
Steps to reproduce the behavior:

# Create new instance of Formatter:
import vestaboard
fm = vestaboard.Formatter()

# Convert string:
fm.convertLine('THU{0}{0}{0}{0}{0}{0}{63}{64}{65}{66}{67}{68}{69}{0}{0}{0}{0}{0}{0}')
# Fails with 'string index out of range'

Expected behavior
The convertLine() method should convert any input string containing valid characters as long as the string has a length of <= 22. Valid character codes can be found on Vestaboard's Character Code reference page.. convertLine() should return a list of integers once conversion is complete.

Additional context
This bug seems to only affect strings that end with bracket-encoded characters of a single digit. The below line works, for example, and does not throw an error:
fm.convertLine('{0}{0}{0}{0}{0}{0}{63}{64}{65}{66}{67}{68}{69}{0}{0}{0}{0}{0}{0}THU')
Possibility the issue is actually with bracket-encoded characters at the end of the input string, where searching for the closing (matching) bracket would cause an attempted string access at an index which is beyond the length of the string.

Current Workaround
Replace bracket-encoded characters with their actual values - for example, use spaces instead of {0}. Note that when using the vestaboard.Board().post() method, this may not work as Vestaboard's endpoint strips out leading and trailing whitespace when using the .post() method.
Check file vestaboard/formatter.py on line 79 - I believe this is where the error is throwing. There is a check for a closing bracket 2 characters over (a two-digit character code), but when the string ends with a one-digit code, that could cause the error as the formatter will be attempting to access the string at an index beyond the length of the string.

@ShaneSutro ShaneSutro added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed labels Jun 17, 2021
@ShaneSutro ShaneSutro linked a pull request Jul 22, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant