From 3ad9449b06a84566273367b89447502f15da8ef7 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Fri, 17 Nov 2023 10:10:42 +0100 Subject: [PATCH] validate string before parsing --- lib/elixir_sense/core/parser.ex | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/elixir_sense/core/parser.ex b/lib/elixir_sense/core/parser.ex index 9e716592..d0a2ec37 100644 --- a/lib/elixir_sense/core/parser.ex +++ b/lib/elixir_sense/core/parser.ex @@ -16,12 +16,17 @@ defmodule ElixirSense.Core.Parser do def parse_file(file, try_to_fix_parse_error, try_to_fix_line_not_found, cursor_line_number) do case File.read(file) do {:ok, source} -> - parse_string( - source, - try_to_fix_parse_error, - try_to_fix_line_not_found, - cursor_line_number - ) + if String.valid?(source) do + parse_string( + source, + try_to_fix_parse_error, + try_to_fix_line_not_found, + cursor_line_number + ) + else + Logger.warning("Invalid encoding in #{file}") + create_metadata("", {:error, :invalid_encoding}) + end error -> Logger.warning("Unable to read file #{file}: #{inspect(error)}")