Merge lp:~3v1n0/unity/desktop-utilities-unescape-paths into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Michal Hruby
Approved revision: no longer in the source branch.
Merged at revision: 2801
Proposed branch: lp:~3v1n0/unity/desktop-utilities-unescape-paths
Merge into: lp:unity
Diff against target: 97 lines (+33/-9)
2 files modified
UnityCore/DesktopUtilities.cpp (+18/-6)
tests/test_desktop_utilities.cpp (+15/-3)
To merge this branch: bzr merge lp:~3v1n0/unity/desktop-utilities-unescape-paths
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+127590@code.launchpad.net

Commit message

DesktopUtilities: unescape the desktop paths and ids before processing them

Description of the change

When computing the DesktopID or the file path from a DesktopID, we need to make sure that the processed file has been escaped.

Unit tests added.

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

Is this really what we want to do? We should properly distinguish methods that accept paths vs methods that work with URIs. Otherwise the next bug we'll get is "Unable to add desktop files with [insert special symbol here] in their name".

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Mh, in effect this seems to happen now if a file name has contains a '%', while dragging it from dash... But at this point I would say that the lens should use the same format of the file managers and so always escaping these file URIs, or it won't be always possible to distinguish them.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Note: This is already committed to lp:unity/6.0 before lp:unity!

Revision history for this message
Michal Hruby (mhr3) wrote :

I have my doubts about this, but let's at least keep trunk in sync with 6.0 and perhaps fix it up later.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/DesktopUtilities.cpp'
2--- UnityCore/DesktopUtilities.cpp 2012-09-07 14:32:44 +0000
3+++ UnityCore/DesktopUtilities.cpp 2012-10-02 21:09:22 +0000
4@@ -87,6 +87,12 @@
5 if (desktop_path.empty())
6 return "";
7
8+ glib::String unescaped(g_uri_unescape_string(desktop_path.c_str(), NULL));
9+ std::string const& desktop_file = unescaped.Str();
10+
11+ if (desktop_file.empty())
12+ return "";
13+
14 for (auto dir : default_paths)
15 {
16 if (!dir.empty())
17@@ -100,11 +106,11 @@
18 dir.append(G_DIR_SEPARATOR_S "applications" G_DIR_SEPARATOR_S);
19 }
20
21- if (desktop_path.find(dir) == 0)
22+ if (desktop_file.find(dir) == 0)
23 {
24 // if we are in a subdirectory of system path, the store name should
25 // be subdir-filename.desktop
26- std::string desktop_suffix = desktop_path.substr(dir.size());
27+ std::string desktop_suffix = desktop_file.substr(dir.size());
28 std::replace(desktop_suffix.begin(), desktop_suffix.end(), G_DIR_SEPARATOR, '-');
29
30 return desktop_suffix;
31@@ -112,7 +118,7 @@
32 }
33 }
34
35- return desktop_path;
36+ return desktop_file;
37 }
38
39 std::string DesktopUtilities::GetDesktopID(std::string const& desktop_path)
40@@ -126,12 +132,18 @@
41 if (desktop_id.empty())
42 return "";
43
44+ glib::String unescaped_id(g_uri_unescape_string(desktop_id.c_str(), NULL));
45+ std::string const& id = unescaped_id.Str();
46+
47+ if (id.empty())
48+ return "";
49+
50 glib::Object<GDesktopAppInfo> info;
51
52- if (desktop_id.find(G_DIR_SEPARATOR_S) != std::string::npos)
53- info = g_desktop_app_info_new_from_filename(desktop_id.c_str());
54+ if (id.find(G_DIR_SEPARATOR_S) != std::string::npos)
55+ info = g_desktop_app_info_new_from_filename(id.c_str());
56 else
57- info = g_desktop_app_info_new(desktop_id.c_str());
58+ info = g_desktop_app_info_new(id.c_str());
59
60 if (info)
61 {
62
63=== modified file 'tests/test_desktop_utilities.cpp'
64--- tests/test_desktop_utilities.cpp 2012-09-18 15:47:49 +0000
65+++ tests/test_desktop_utilities.cpp 2012-10-02 21:09:22 +0000
66@@ -36,9 +36,6 @@
67 TEST(TestDesktopUtilitiesDesktopID, TestEmptyValues)
68 {
69 std::vector<std::string> empty_list;
70-
71- EXPECT_THAT(DesktopUtilities::GetDesktopID(empty_list, "/some/path/to.desktop"),
72- Eq("/some/path/to.desktop"));
73 EXPECT_THAT(DesktopUtilities::GetDesktopID(empty_list, "/some/path/to.desktop"),
74 Eq("/some/path/to.desktop"));
75
76@@ -77,6 +74,21 @@
77 Eq("/some/path/applications/to.desktop"));
78 }
79
80+TEST(TestDesktopUtilitiesDesktopID, TestUnescapePath)
81+{
82+ std::vector<std::string> dirs;
83+
84+ dirs.push_back("/this/ path");
85+ dirs.push_back("/that/path /");
86+
87+ EXPECT_THAT(DesktopUtilities::GetDesktopID(dirs, "/this/%20path/applications/to%20file.desktop"),
88+ Eq("to file.desktop"));
89+ EXPECT_THAT(DesktopUtilities::GetDesktopID(dirs, "/that/path%20/applications/to%20file.desktop"),
90+ Eq("to file.desktop"));
91+ EXPECT_THAT(DesktopUtilities::GetDesktopID(dirs, "/some/path/applications/to%20file.desktop"),
92+ Eq("/some/path/applications/to file.desktop"));
93+}
94+
95 TEST(TestDesktopUtilitiesDesktopID, TestSubdirectory)
96 {
97 std::vector<std::string> dirs;