commit 0823b4a5
Add extra checks to ensure that we only look at the lines in user-dirs.dirs trat are on the format XDG_xxx_DIR="$HOME/yyy" or XDG_xxx_DIR="/yyy"
This prevents trouble caused by future standards that may allow other kind of environments in the user-dirs.dirs-file.
We now allow trailing whitespace. Previously trailing whitespace would make the returned value longer.
We do not allow whitespace around the "=" (and never did). "/usr/bin/xdg-user-dir" fails on it too.
The check is very basic. I had to drop regex. gcc does not support it until 4.9. Current target is 4.8.4
Changed files
| M | sago/platform_folders.cpp before |
diff --git a/sago/platform_folders.cpp b/sago/platform_folders.cpp
index 9bf1593..4f89040 100644
--- a/sago/platform_folders.cpp
+++ b/sago/platform_folders.cpp
@@ -253,13 +253,20 @@ static void PlatformFoldersAddFromFile(const std::string& filename, std::map<std
std::ifstream infile(filename.c_str());
std::string line;
while (std::getline(infile, line)) {
- if (line.length() == 0 || line.at(0) == '#') {
+ if (line.length() == 0 || line.at(0) == '#' || line.substr(0, 4) != "XDG_" || line.find("_DIR") == std::string::npos) {
+ continue;
+ }
+ try {
+ std::size_t splitPos = line.find('=');
+ std::string key = line.substr(0, splitPos);
+ std::size_t valueStart = line.find('"', splitPos);
+ std::size_t valueEnd = line.find('"', valueStart+1);
+ std::string value = line.substr(valueStart+1, valueEnd - valueStart - 1);
+ folders[key] = value;
+ } catch (std::exception& e) {
+ std::cerr << "WARNING: Failed to process \"" << line << "\" from \"" << filename << "\". Error: "<< e.what() << "\n";
continue;
}
- std::size_t splitPos = line.find("=");
- std::string key = line.substr(0, splitPos);
- std::string value = line.substr(splitPos+2, line.length()-splitPos-3);
- folders[key] = value;
}
}