Merge lp:~abreu-alexandre/webbrowser-app/enhance-google-url-patterns into lp:webbrowser-app

Proposed by Alexandre Abreu
Status: Merged
Approved by: Alexandre Abreu
Approved revision: 1278
Merged at revision: 1344
Proposed branch: lp:~abreu-alexandre/webbrowser-app/enhance-google-url-patterns
Merge into: lp:webbrowser-app
Diff against target: 59 lines (+17/-2)
2 files modified
src/app/webcontainer/url-pattern-utils.cpp (+8/-2)
tests/unittests/container-url-patterns/tst_ContainerUrlPatternsTests.cpp (+9/-0)
To merge this branch: bzr merge lp:~abreu-alexandre/webbrowser-app/enhance-google-url-patterns
Reviewer Review Type Date Requested Status
Olivier Tilloy Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+278025@code.launchpad.net

Commit message

Enhance google.com specific patterns to enable co.* & com.* patterns

Description of the change

Enhance google.com specific patterns to enable co.* & com.* patterns

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

LGTM. Note that with this, "http://google.com.com" becomes valid, but it’s obviously not a valid google domain. Does that matter?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/webcontainer/url-pattern-utils.cpp'
2--- src/app/webcontainer/url-pattern-utils.cpp 2014-11-19 14:38:16 +0000
3+++ src/app/webcontainer/url-pattern-utils.cpp 2015-11-19 15:45:20 +0000
4@@ -63,7 +63,9 @@
5 * <url-pattern> := <scheme>://<host><path>
6 * <scheme> := 'http' | 'https'
7 * <host> := <any char except '/', '*', '?' and '.'>+ '.google' <hostpart>
8- * <hostpart> := '.' <any char except '/', '?' and '.'>+
9+ * <hostpart> := '.' ( <restricted-sld-part> | <tld-part> )
10+ * <restricted-sld-part> := ('com' | 'co') '.' <tld-part>
11+ * <tld-part> := <any char except '/', '?' and '.'>+
12 * <path> := '/' <any chars>
13 *
14 * So for example we allow 'https://accounts.google.* /' but not 'https://*.google.* /'
15@@ -72,12 +74,16 @@
16 * IMPORTAN NOTE: the '*' wildcard in the TLD position is not a REAL wildcard in the
17 * sense that it corresponds to [^\\./], so it wont match ('google.com.evildomain') as usual.
18 *
19+ * The <restricted-sld-part> non-terminal in the grammar above comes from:
20+ *
21+ * https://en.wikipedia.org/wiki/List_of_Google_domains
22+ *
23 * @param pattern pattern that is to be tested for validity
24 * @return true if the url is valid, false otherwise
25 */
26 bool isValidGoogleUrlPattern(const QString& pattern)
27 {
28- static QRegularExpression grammar("^http(s|s\\?)?://[^\\.\\?\\*]+\\.google\\.[^\\.\\?]+/.*$");
29+ static QRegularExpression grammar("^http(s|s\\?)?://[^\\.\\?\\*]+\\.google\\.((com|co)\\.)?[^\\.\\?]+/.*$");
30 return grammar.match(pattern).hasMatch();
31 }
32
33
34=== modified file 'tests/unittests/container-url-patterns/tst_ContainerUrlPatternsTests.cpp'
35--- tests/unittests/container-url-patterns/tst_ContainerUrlPatternsTests.cpp 2014-09-12 17:58:10 +0000
36+++ tests/unittests/container-url-patterns/tst_ContainerUrlPatternsTests.cpp 2015-11-19 15:45:20 +0000
37@@ -83,6 +83,14 @@
38 << "https?://mail.google.*/*"
39 << "https?://mail.google.[^\\./]*/[^\\s]*" << true;
40
41+ QTest::newRow("Valid Google com SLD pattern")
42+ << "https?://mail.google.com.*/*"
43+ << "https?://mail.google.com.[^\\./]*/[^\\s]*" << true;
44+
45+ QTest::newRow("Valid Google co SLD pattern")
46+ << "https?://mail.google.co.*/*"
47+ << "https?://mail.google.co.[^\\./]*/[^\\s]*" << true;
48+
49 QTest::newRow("Valid non Google pattern")
50 << "https://*.google.com/*"
51 << "https://[^\\./]*.google.com/[^\\s]*" << true;
52@@ -100,6 +108,7 @@
53 WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(6, "https://se*rv?ice.goo*gle.com/*");
54 WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(7, "https://se*rvice.goo*gle.com/*");
55 WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(8, "https://se*rvice.goo*gle.*/*");
56+ WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(8, "https://service.google.kom.*/*");
57 }
58
59 void transformedUrlPatterns()

Subscribers

People subscribed via source and target branches

to status/vote changes: