Skip to content

Commit fdd380f

Browse files
committed
Don't crash if text file contains invalid utf8
1 parent 9c36d6b commit fdd380f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tmc-langs-framework/src/meta_syntax.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ impl<B: BufRead> Iterator for MetaSyntaxParser<B> {
110110
type Item = Result<MetaString, TmcError>;
111111

112112
fn next(&mut self) -> Option<Self::Item> {
113-
let mut s = String::new();
114-
match self.reader.read_line(&mut s) {
113+
let mut raw_string_buffer: Vec<u8> = Vec::new();
114+
115+
match self.reader.read_until(b'\n', &mut raw_string_buffer) {
115116
// read 0 bytes = reader empty = iterator empty
116117
Ok(0) => None,
117118
Ok(_) => {
119+
let mut s = String::from_utf8_lossy(&raw_string_buffer).to_string();
118120
// check line with each meta syntax
119121
for meta_syntax in self.meta_syntaxes {
120122
// check for stub

0 commit comments

Comments
 (0)