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