1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00

fix(config_parser): Gracefully handle BOM (#2166)

* fix(config_parser): Gracefully handle BOM

* Move check to parse_line function

And clarify the error message

Closes #2075
This commit is contained in:
Nolan Prochnau 2020-08-15 06:02:23 -04:00 committed by GitHub
parent a4dd2a93d6
commit 2f4cffc0fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -1,8 +1,8 @@
#include "components/config_parser.hpp"
#include <algorithm>
#include <fstream>
#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,7 +198,7 @@ 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 {
@ -201,6 +206,7 @@ line_type config_parser::get_line_type(const string& line) {
}
}
}
}
string config_parser::parse_header(const string& line) {
if (line.back() != ']') {

View file

@ -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);
}
// }}}