Skip to content

Commit 4b98b6c

Browse files
committed
Initial commit didn't contain latest changes
1 parent f2a996d commit 4b98b6c

File tree

2 files changed

+98
-3
lines changed

2 files changed

+98
-3
lines changed

src/desktopfilereader.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,29 @@ namespace linuxdeploy {
9898
(c >= 'A' && c <= 'Z') ||
9999
(c >= 'a' && c <= 'z') ||
100100
(c >= '0' && c <= '9') ||
101-
(c == '-')
102-
))
103-
throw ParseError("Key contains invalid character " + std::string{c});
101+
(c == '-') ||
102+
// FIXME: remove this hack after introducing localization support to
103+
// conform to desktop file spec again
104+
(c == '[') || (c == ']')
105+
)
106+
) {
107+
throw ParseError(
108+
"Key " + key + " contains invalid character " + std::string{c}
109+
);
110+
}
111+
}
112+
113+
if (std::count(key.begin(), key.end(), '[') > 1 ||
114+
std::count(key.begin(), key.end(), ']') > 1 ||
115+
// make sure that both [ and ] are present
116+
(key.find('[') != std::string::npos && key.find(']') == std::string::npos) ||
117+
(key.find('[') == std::string::npos && key.find(']') != std::string::npos) ||
118+
// disallow empty locale names
119+
(key.find('[') != std::string::npos && key.find(']') != std::string::npos && (key.find(']') - key.find('[')) < 2) ||
120+
// ensure order of [ and ]
121+
(key.find('[') != std::string::npos && key.find('[' ) > key.find(']'))
122+
) {
123+
throw ParseError("Invalid localization syntax used in key " + key);
104124
}
105125

106126
auto& section = sections[currentSectionName];

tests/test_desktopfilereader.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,78 @@ TEST_F(DesktopFileReaderTest, testReadBrokenSectionMissingOpeningBracket) {
388388
EXPECT_THROW(DesktopFileReader reader(ins), ParseError);
389389
}
390390
}
391+
392+
// FIXME: introduce proper localization support
393+
TEST_F(DesktopFileReaderTest, testReadLocalizedEntriesWithoutProperLocalizationSupport) {
394+
std::stringstream ss;
395+
ss << "[Desktop File]" << std::endl
396+
<< "Name=name" << std::endl
397+
<< "Name[de]=name" << std::endl
398+
<< "Exec=exec" << std::endl;
399+
400+
DesktopFileReader reader(ss);
401+
402+
auto section = reader["Desktop File"];
403+
EXPECT_FALSE(section.empty());
404+
405+
auto data = reader.data();
406+
407+
auto expected = DesktopFile::section_t({
408+
{"Name", DesktopFileEntry("Name", "name")},
409+
// FIXME: revise after introduction of localization support
410+
{"Name[de]", DesktopFileEntry("Name[de]", "name")},
411+
{"Exec", DesktopFileEntry("Exec", "exec")},
412+
});
413+
414+
EXPECT_EQ(data["Desktop File"], expected);
415+
}
416+
417+
TEST_F(DesktopFileReaderTest, testBrokenLocalizedKeys) {
418+
{
419+
std::stringstream ins;
420+
ins << "[Desktop Entry]" << std::endl
421+
<< "test]de[=test" << std::endl;
422+
423+
EXPECT_THROW(DesktopFileReader reader(ins), ParseError);
424+
}
425+
426+
{
427+
std::stringstream ins;
428+
ins << "[Desktop Entry]" << std::endl
429+
<< "test[de]]=test" << std::endl;
430+
431+
EXPECT_THROW(DesktopFileReader reader(ins), ParseError);
432+
}
433+
434+
{
435+
std::stringstream ins;
436+
ins << "[Desktop Entry]" << std::endl
437+
<< "test[[de]=test" << std::endl;
438+
439+
EXPECT_THROW(DesktopFileReader reader(ins), ParseError);
440+
}
441+
442+
{
443+
std::stringstream ins;
444+
ins << "[Desktop Entry]" << std::endl
445+
<< "test[]de=test" << std::endl;
446+
447+
EXPECT_THROW(DesktopFileReader reader(ins), ParseError);
448+
}
449+
450+
{
451+
std::stringstream ins;
452+
ins << "[Desktop Entry]" << std::endl
453+
<< "test[de=test" << std::endl;
454+
455+
EXPECT_THROW(DesktopFileReader reader(ins), ParseError);
456+
}
457+
458+
{
459+
std::stringstream ins;
460+
ins << "[Desktop Entry]" << std::endl
461+
<< "testde]=test" << std::endl;
462+
463+
EXPECT_THROW(DesktopFileReader reader(ins), ParseError);
464+
}
465+
}

0 commit comments

Comments
 (0)