Merge lp:~ted/url-dispatcher/more-sophisticated-urls into lp:url-dispatcher/rtm-14.09

Proposed by Ted Gould
Status: Merged
Approved by: Charles Kerr
Approved revision: 82
Merged at revision: 75
Proposed branch: lp:~ted/url-dispatcher/more-sophisticated-urls
Merge into: lp:url-dispatcher/rtm-14.09
Diff against target: 76 lines (+43/-1)
2 files modified
service/dispatcher.c (+2/-1)
tests/dispatcher-test.cc (+41/-0)
To merge this branch: bzr merge lp:~ted/url-dispatcher/more-sophisticated-urls
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+240006@code.launchpad.net

This proposal supersedes a proposal from 2014-10-23.

Commit message

Making generic regular expression more robust

Description of the change

Turns out some people need some more flexibility in our URLs. Let's give it to them.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote : Posted in a previous version of this proposal

Not sure about magnet links, but for DialerTest, shouldn’t we also test that a URL of the form "tel:///+442031485000" (i.e. with slashes) is valid? I don’t know how frequent this kind of link is around the web, but given that both forms are theoretically valid, we should assume we’ll encounter both.

Revision history for this message
Charles Kerr (charlesk) wrote : Posted in a previous version of this proposal

The patch LGTM.

I don't know how common tel:/// is and at first glance it doesn't seem to conform to RFC 3966... unless there's at least some anecdotal evidence that tel:/// is frequent in the wild, I'd vote against it.

Ted, looks like this MP predates the branching your scripts did last week. Does this need to be submitted against /14.10 as well?

review: Approve
Revision history for this message
Charles Kerr (charlesk) :
review: Approve
Revision history for this message
Olivier Tilloy (osomon) wrote :

It seems that "tel:///" is not correct indeed. Although I couldn’t find proper anecdotal evidence, this question on stackoverflow (http://stackoverflow.com/questions/22704662/using-slashes-in-tel-uris) seems to imply that there are tel links in the wild with two slashes (which is definitely incorrect).

As I understand it, the generic RE is used for matching "http" URLs as well as "tel", so unless we introduce a more specific RE for matching "tel" URLs, the generic RE will accept "tel" links with slashes, right?

I don’t think that’s a big deal though, the issue at hand (handling "tel:" links) is fixed, the logic can probably be refined later with a lower priority.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'service/dispatcher.c'
2--- service/dispatcher.c 2014-09-22 14:46:06 +0000
3+++ service/dispatcher.c 2014-10-29 14:48:52 +0000
4@@ -370,6 +370,7 @@
5 gchar * domain = g_match_info_fetch(genericmatch, 2);
6
7 *out_appid = url_db_find_url(urldb, protocol, domain);
8+ g_debug("Protocol '%s' for domain '%s' resulting in app id '%s'", protocol, domain, *out_appid);
9
10 if (*out_appid != NULL) {
11 found = TRUE;
12@@ -448,7 +449,7 @@
13
14 applicationre = g_regex_new("^application:///([a-zA-Z0-9_\\.-]*)\\.desktop$", 0, 0, NULL);
15 appidre = g_regex_new("^appid://([a-z0-9\\.-]*)/([a-zA-Z0-9-]*)/([a-zA-Z0-9\\.-]*)$", 0, 0, NULL);
16- genericre = g_regex_new("^(.*)://([a-z0-9\\.-]*)?/?(.*)?$", 0, 0, NULL);
17+ genericre = g_regex_new("^([a-z][a-z0-9]*):(?://(?:.*@)(a-z0-9\\.-]*)(?::[0-9])/)?(.*)?$", 0, 0, NULL);
18
19 g_bus_get(G_BUS_TYPE_SESSION, cancellable, bus_got, mainloop);
20
21
22=== modified file 'tests/dispatcher-test.cc'
23--- tests/dispatcher-test.cc 2014-09-22 14:46:06 +0000
24+++ tests/dispatcher-test.cc 2014-10-29 14:48:52 +0000
25@@ -43,6 +43,12 @@
26 url_db_set_file_motification_time(db, "/testdir/com.ubuntu.calendar_calendar_9.8.2343.url-dispatcher", &timestamp);
27 url_db_insert_url(db, "/testdir/com.ubuntu.calendar_calendar_9.8.2343.url-dispatcher", "calendar", NULL);
28
29+ url_db_set_file_motification_time(db, "/testdir/com.ubuntu.dialer_dialer_1234.url-dispatcher", &timestamp);
30+ url_db_insert_url(db, "/testdir/com.ubuntu.dialer_dialer_1234.url-dispatcher", "tel", NULL);
31+
32+ url_db_set_file_motification_time(db, "/testdir/magnet-test.url-dispatcher", &timestamp);
33+ url_db_insert_url(db, "/testdir/magnet-test.url-dispatcher", "magnet", NULL);
34+
35 sqlite3_close(db);
36
37 testbus = g_test_dbus_new(G_TEST_DBUS_NONE);
38@@ -152,3 +158,38 @@
39
40 return;
41 }
42+
43+TEST_F(DispatcherTest, DialerTest)
44+{
45+ gchar * out_appid = NULL;
46+ const gchar * out_url = NULL;
47+
48+ /* Base Telephone */
49+ EXPECT_TRUE(dispatcher_url_to_appid("tel:+442031485000", &out_appid, &out_url));
50+ EXPECT_STREQ("com.ubuntu.dialer_dialer_1234", out_appid);
51+ g_free(out_appid);
52+
53+ /* Tel with bunch of commas */
54+ EXPECT_TRUE(dispatcher_url_to_appid("tel:911,,,1,,1,,2", &out_appid, &out_url));
55+ EXPECT_STREQ("com.ubuntu.dialer_dialer_1234", out_appid);
56+ g_free(out_appid);
57+
58+ /* Telephone with slashes */
59+ EXPECT_TRUE(dispatcher_url_to_appid("tel:///+442031485000", &out_appid, &out_url));
60+ EXPECT_STREQ("com.ubuntu.dialer_dialer_1234", out_appid);
61+ g_free(out_appid);
62+
63+ return;
64+}
65+
66+TEST_F(DispatcherTest, MagnetTest)
67+{
68+ gchar * out_appid = NULL;
69+ const gchar * out_url = NULL;
70+
71+ EXPECT_TRUE(dispatcher_url_to_appid("magnet:?xt=urn:ed2k:31D6CFE0D16AE931B73C59D7E0C089C0&xl=0&dn=zero_len.fil&xt=urn:bitprint:3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ.LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ&xt=urn:md5:D41D8CD98F00B204E9800998ECF8427E", &out_appid, &out_url));
72+ EXPECT_STREQ("magnet-test", out_appid);
73+ g_free(out_appid);
74+
75+ return;
76+}

Subscribers

People subscribed via source and target branches