File tree 2 files changed +37
-2
lines changed
2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -354,9 +354,12 @@ class Mode(object):
354
354
while not line [5 :].strip ().endswith (')' ):
355
355
line = line .split ('//' )[0 ]
356
356
if sys .version_info > (3 , 0 ): # is there a clean way to to it?
357
- line += ' ' + f .readline ().decode (sym_import_encoding ). strip ( )
357
+ next_line = f .readline ().decode (sym_import_encoding )
358
358
else :
359
- line += ' ' + next (f ).decode (sym_import_encoding ).strip ()
359
+ next_line = next (f ).decode (sym_import_encoding )
360
+ if next_line is "" :
361
+ raise EOFError ("Reached EOF before finding terminator for enum :\" {}\" " .format (line ))
362
+ line += next_line .strip ()
360
363
line = line .split ('//' )[0 ]
361
364
temp_array = line [5 :].strip ().rstrip (')' ).split ('(' , 1 )
362
365
val_table_name = temp_array [0 ]
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
import io
3
+ import sys
3
4
import textwrap
4
5
5
6
import pytest
@@ -141,3 +142,34 @@ def tests_parse_float(variable_type, bit_length):
141
142
frame = matrix .frames [0 ]
142
143
signal = frame .signals [0 ]
143
144
assert signal .is_float
145
+
146
+ def test_unterminated_enum ():
147
+ f = io .BytesIO (
148
+ textwrap .dedent (
149
+ '''\
150
+ FormatVersion=5.0 // Do not edit this line!
151
+ Title="Untitled
152
+
153
+ {ENUMS}
154
+ enum Categories(0="Animal", 1="Vegetable", 3="Mineral"
155
+
156
+ {SENDRECEIVE}
157
+
158
+ [Symbol1]
159
+ ID=000h
160
+ DLC=8
161
+ Var=Signal unsigned 0,16
162
+
163
+ '''
164
+ ).encode ('utf-8' ),
165
+ )
166
+ # Missing ')' at the end of enum used to cause infinite loop
167
+
168
+ matrix = canmatrix .formats .sym .load (f )
169
+
170
+ assert len (matrix .load_errors ) == 1
171
+ if sys .version_info > (3 , 0 ):
172
+ assert isinstance (matrix .load_errors [0 ], EOFError )
173
+ else :
174
+ assert isinstance (matrix .load_errors [0 ], StopIteration )
175
+
You can’t perform that action at this time.
0 commit comments