__ 1. Spurious spaces when reading unquoted strings. __
Test program:
:::basic10INPUTZ$20PRINTZ$
Run the program and when prompted enter:
AAA BBB
The program responds:
AAA B B B
Note the extra spaces introduced between the Bs.
The fix is a one liner in routine "input_entry" in file "representation.py":
:::python
def input_entry(text_file, allow_quotes, end_all=(), end_not_quoted=(',',)):
word, blanks = '', ''
# skip leading spaces and line feeds and NUL.
c = text_skip(text_file, ascii_white)
if c in end_all + end_not_quoted:
return ''
quoted = (c == '"' and allow_quotes)
if quoted:
text_file.read_chars(1)
while True:
# read entry
if text_file.end_of_file():
break
c = ''.join(text_file.read_chars(1))
if c in end_all or (c in end_not_quoted and not quoted):
# on KYBD: text file, this will do nothing - comma is swallowed
text_file.seek(-len(c), 1)
break
elif c == '"' and quoted:
quoted = False
# ignore blanks after the quotes
c = text_skip(text_file, ascii_white)
break
elif c in ascii_white and not quoted:
blanks += c
else:
word += blanks + c
blanks = '' # WJB - clear blanks after reading a non-blank character
if len(word)+len(blanks) >= 255:
text_file.seek(-len(c), 1)
break
return word
__ 2. Error reading numeric value on one line, followed by text string on the next. __
The numeric value is followed by <space><cr><lf>. The existing code just skips the trailing space, leaving the file pointer at the end of line. So the following text input just reads an empty string. It is necessary to skip all trailing white space and possibly one end of line after reading a value. The fix is in routine "input_vars_file", again in "representation.py":</lf></cr></space>
:::pythondefinput_vars_file(readvar,text_file):forvinreadvar:typechar=v[0][-1]iftypechar=='$':valstr=input_entry(text_file,allow_quotes=True,end_all=('\r','\x1a'),end_not_quoted=(',','\n'))print('Read string "%s" from file'%valstr)else:valstr=input_entry(text_file,allow_quotes=False,end_all=('\r','\x1a',',','\n',' '))print('Read value %s from file'%valstr)value=str_to_type(valstr,typechar)ifvalue==None:value=vartypes.null[typechar]#processtheendingchar(thismayraiseFIELDOVERFLOWbutshouldavoidINPUTPASTEND)ifnottext_file.end_of_file()andtext_file.peek_char()notin('','\x1a'):text_file.read_chars(1)#WJB-Skiptrailingspaceandanendoflinwtext_skip(text_file,ascii_white)ifnottext_file.end_of_file()andtext_file.peek_char()=='\r':text_file.read_chars(1)ifnottext_file.end_of_file()andtext_file.peek_char()=='\n':text_file.read_chars(1)#andthensetthevaluev.append(value)returnreadvar
Regards,
WJB
Don't seem to be able to get code formatting to work, sorry.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi WJB, thanks for reporting the bugs and for your patches!
I believe bug #1 has been fixed, at least in the development branch, but it's probably still there in the latest package release - I'll check and do a bugfix release.
I'll have a look at your test case and patch for bug #2.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have found a couple of input bugs:
__ 1. Spurious spaces when reading unquoted strings. __
Test program:
Run the program and when prompted enter:
AAA BBB
The program responds:
AAA B B B
Note the extra spaces introduced between the Bs.
The fix is a one liner in routine "input_entry" in file "representation.py":
__ 2. Error reading numeric value on one line, followed by text string on the next. __
Test program:
This displays:
314
END
The "Test String" is not read. Dumping the test data file shows:
The numeric value is followed by <space><cr><lf>. The existing code just skips the trailing space, leaving the file pointer at the end of line. So the following text input just reads an empty string. It is necessary to skip all trailing white space and possibly one end of line after reading a value. The fix is in routine "input_vars_file", again in "representation.py":</lf></cr></space>
Regards,
WJB
Don't seem to be able to get code formatting to work, sorry.
Hi WJB, thanks for reporting the bugs and for your patches!
I believe bug #1 has been fixed, at least in the development branch, but it's probably still there in the latest package release - I'll check and do a bugfix release.
I'll have a look at your test case and patch for bug #2.
I've implemented your fix, slightly modified to account for comma-separated values. Thanks!
These bugs are now fixed with release 14.04.5.