diff --git a/src/components/config_parser.cpp b/src/components/config_parser.cpp index 3adf6e00..eb3e0676 100644 --- a/src/components/config_parser.cpp +++ b/src/components/config_parser.cpp @@ -1,8 +1,8 @@ +#include "components/config_parser.hpp" + #include #include -#include "components/config_parser.hpp" - POLYBAR_NS config_parser::config_parser(const logger& logger, string&& file, string&& bar) @@ -151,6 +151,11 @@ void config_parser::parse_file(const string& file, file_list path) { } line_t config_parser::parse_line(const string& line) { + if (string_util::contains(line, "\ufeff")) { + throw syntax_error( + "This config file uses UTF-8 with BOM, which is not supported. Please use plain UTF-8 without BOM."); + } + string line_trimmed = string_util::trim(line, isspace); line_type type = get_line_type(line_trimmed); @@ -193,12 +198,13 @@ line_type config_parser::get_line_type(const string& line) { case '#': return line_type::COMMENT; - default: + default: { if (string_util::contains(line, "=")) { return line_type::KEY; } else { return line_type::UNKNOWN; } + } } } diff --git a/tests/unit_tests/components/config_parser.cpp b/tests/unit_tests/components/config_parser.cpp index 7766f7d4..5aa7c43e 100644 --- a/tests/unit_tests/components/config_parser.cpp +++ b/tests/unit_tests/components/config_parser.cpp @@ -1,4 +1,5 @@ #include "components/config_parser.hpp" + #include "common/test.hpp" #include "components/logger.hpp" @@ -98,6 +99,7 @@ TEST_P(ParseLineKeyTest, correctness) { TEST_F(ParseLineInValidTest, throwsSyntaxError) { EXPECT_THROW(parser->parse_line("unknown"), syntax_error); + EXPECT_THROW(parser->parse_line("\ufeff"), syntax_error); } // }}}