Skip to content

Commit 0871018

Browse files
committed
Stricter check for "ENVI" on first line of header file.
Previously, we only checked that the word "ENVI" appeared on the first line of the header file. So a first line stating "This is not an ENVI file" would be considered an ENVI header. Now, we check that "ENVI" are the first 4 non-whitespace characters in the file.
1 parent d7a17f2 commit 0871018

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

spectral/io/envi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,16 @@ def read_envi_header(file):
124124
f = builtins.open(file, 'r')
125125

126126
try:
127-
pos = f.readline().find("ENVI")
127+
starts_with_ENVI = f.readline().strip().startswith('ENVI')
128128
except UnicodeDecodeError:
129129
msg = 'File does not appear to be an ENVI header (appears to be a ' \
130130
'binary file).'
131131
f.close()
132132
raise FileNotAnEnviHeader(msg)
133133
else:
134-
if pos == -1:
134+
if not starts_with_ENVI:
135135
msg = 'File does not appear to be an ENVI header (missing "ENVI" \
136-
on first line).'
136+
at beginning of first line).'
137137
f.close()
138138
raise FileNotAnEnviHeader(msg)
139139

0 commit comments

Comments
 (0)