Recognize broken section headings, mk. 4

This commit is contained in:
TheAssassin
2018-11-14 11:14:24 +01:00
parent 4a07c8151e
commit 80adfa8872
2 changed files with 25 additions and 2 deletions

View File

@@ -78,9 +78,13 @@ namespace linuxdeploy {
if (currentSectionName.empty())
throw ParseError("No section in desktop file");
auto delimiterPos = line.find('=');
if (delimiterPos == std::string::npos)
throw ParseError("No = key/value delimiter found");
// this line should be a normal key-value pair
std::string key = line.substr(0, line.find('='));
std::string value = line.substr(line.find('=') + 1, line.size());
std::string key = line.substr(0, delimiterPos);
std::string value = line.substr(delimiterPos + 1, line.size());
// we can strip away any sort of leading or trailing whitespace safely
linuxdeploy::util::trim(key);

View File

@@ -261,3 +261,22 @@ TEST_F(DesktopFileReaderFixture, testReadBrokenSectionHeaderTooManyOpeningBracke
ASSERT_THROW(DesktopFileReader reader(ins), ParseError);
}
}
TEST_F(DesktopFileReaderFixture, testReadBrokenSectionMissingOpeningBracket) {
{
std::stringstream ins;
ins << "Desktop Entry]" << std::endl
<< "test=test" << std::endl;
ASSERT_THROW(DesktopFileReader reader(ins), ParseError);
}
// also test for brokenness in a later section, as the first section is normally treated specially
{
std::stringstream ins;
ins << "[Desktop Entry]" << std::endl
<< "test=test" << std::endl
<< "Another Section]" << std::endl;
ASSERT_THROW(DesktopFileReader reader(ins), ParseError);
}
}