mirror of
https://github.com/audacity/linuxdeploy.git
synced 2026-04-12 21:25:04 -05:00
Recognize broken section headings, mk. 2
This commit is contained in:
@@ -56,10 +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(']');
|
||||
auto closingBracketPos = line.find(']');
|
||||
auto lastClosingBracketPos = line.find_last_of(']');
|
||||
|
||||
if (closingBracketPos == std::string::npos)
|
||||
throw ParseError("No closing ] bracket in section header");
|
||||
else if (closingBracketPos != lastClosingBracketPos)
|
||||
throw ParseError("Two or more closing ] brackets in section header");
|
||||
|
||||
size_t length = len - 2;
|
||||
auto title = line.substr(1, closingBracketPos - 1);
|
||||
|
||||
@@ -202,10 +202,18 @@ TEST_F(DesktopFileReaderFixture, testParseLinesWithMultipleSpaces) {
|
||||
EXPECT_EQ(section["Name"].value(), "What a great name");
|
||||
}
|
||||
|
||||
TEST_F(DesktopFileReaderFixture, testReadBrokenSectionHeader) {
|
||||
TEST_F(DesktopFileReaderFixture, testReadBrokenSectionHeaderMissingClosingBracket) {
|
||||
std::stringstream ins;
|
||||
ins << "[Desktop Entry" << std::endl
|
||||
<< "test=test" << std::endl;
|
||||
|
||||
ASSERT_THROW(DesktopFileReader reader(ins), ParseError);
|
||||
}
|
||||
|
||||
TEST_F(DesktopFileReaderFixture, testReadBrokenSectionHeaderTooManyClosingBrackets) {
|
||||
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