Recognize broken section headings, mk. 1

This commit is contained in:
TheAssassin
2018-11-14 10:41:47 +01:00
parent fbc1d78122
commit dc8f446ca4
2 changed files with 14 additions and 1 deletions

View File

@@ -56,8 +56,13 @@ namespace linuxdeploy {
!((len >= 2 && (line[0] == '/' && line[1] == '/')) || (len >= 1 && line[0] == '#'))) {
if (line[0] == '[') {
// this line apparently introduces a new section
auto closingBracketPos = line.find_last_of(']');
if (closingBracketPos == std::string::npos)
throw ParseError("No closing ] bracket in section header");
size_t length = len - 2;
auto title = line.substr(1, line.find(']') - 1);
auto title = line.substr(1, closingBracketPos - 1);
// set up the new section
sections.insert(std::make_pair(title, DesktopFile::section_t()));

View File

@@ -201,3 +201,11 @@ TEST_F(DesktopFileReaderFixture, testParseLinesWithMultipleSpaces) {
EXPECT_EQ(section["Name"].value(), "What a great name");
}
TEST_F(DesktopFileReaderFixture, testReadBrokenSectionHeader) {
std::stringstream ins;
ins << "[Desktop Entry" << std::endl
<< "test=test" << std::endl;
ASSERT_THROW(DesktopFileReader reader(ins), ParseError);
}