mirror of
https://github.com/audacity/linuxdeploy.git
synced 2026-04-12 17:02:23 -05:00
Recognize broken section headings, mk. 1
This commit is contained in:
@@ -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()));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user