Merge lp:~osomon/webbrowser-app/encodeURIComponent into lp:webbrowser-app

Proposed by Olivier Tilloy
Status: Merged
Merged at revision: 567
Proposed branch: lp:~osomon/webbrowser-app/encodeURIComponent
Merge into: lp:webbrowser-app
Diff against target: 232 lines (+91/-110)
2 files modified
src/app/AddressBar.qml (+2/-5)
tests/unittests/qml/tst_AddressBar.qml (+89/-105)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/encodeURIComponent
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Ubuntu Phablet Team Pending
Review via email: mp+222372@code.launchpad.net

Commit message

Use encodeURIComponent() to encode search queries entered in the address bar.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/AddressBar.qml'
2--- src/app/AddressBar.qml 2014-05-22 12:38:25 +0000
3+++ src/app/AddressBar.qml 2014-06-06 17:04:26 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright 2013 Canonical Ltd.
7+ * Copyright 2013-2014 Canonical Ltd.
8 *
9 * This file is part of webbrowser-app.
10 *
11@@ -156,10 +156,7 @@
12 }
13
14 function escapeHtmlEntities(query) {
15- function getEscapeCode(entity) {
16- return "%%1".arg(entity.charCodeAt(0).toString(16))
17- }
18- return query.replace(/\W/, getEscapeCode)
19+ return query.replace(/\W/, encodeURIComponent)
20 }
21
22 function buildSearchUrl(query) {
23
24=== modified file 'tests/unittests/qml/tst_AddressBar.qml'
25--- tests/unittests/qml/tst_AddressBar.qml 2014-02-25 13:10:29 +0000
26+++ tests/unittests/qml/tst_AddressBar.qml 2014-06-06 17:04:26 +0000
27@@ -1,5 +1,5 @@
28 /*
29- * Copyright 2013 Canonical Ltd.
30+ * Copyright 2013-2014 Canonical Ltd.
31 *
32 * This file is part of webbrowser-app.
33 *
34@@ -23,110 +23,94 @@
35 TestCase {
36 name: "AddressBar"
37
38- function test_file_no_rewrite() {
39- addressBar.text = "file:///usr/share/doc/ubuntu-online-tour/index.html"
40- addressBar.validate()
41- compare(addressBar.requestedUrl, "file:///usr/share/doc/ubuntu-online-tour/index.html")
42- }
43-
44- function test_http_no_rewrite() {
45- addressBar.text = "http://ubuntu.com"
46- addressBar.validate()
47- compare(addressBar.requestedUrl, "http://ubuntu.com")
48- }
49-
50- function test_https_no_rewrite() {
51- addressBar.text = "https://google.com"
52- addressBar.validate()
53- compare(addressBar.requestedUrl, "https://google.com")
54- }
55-
56- function test_no_scheme_rewrite() {
57- addressBar.text = "ubuntu.com"
58- addressBar.validate()
59- compare(addressBar.requestedUrl, "http://ubuntu.com")
60- }
61-
62- function test_no_ipadress_scheme_rewrite() {
63- addressBar.text = "192.168.1.1"
64- addressBar.validate()
65- compare(addressBar.requestedUrl, "http://192.168.1.1")
66- addressBar.text = "192.168.1.1:8000"
67- addressBar.validate()
68- compare(addressBar.requestedUrl, "http://192.168.1.1:8000")
69- addressBar.text = "192.168.1.1:8000/dummy.html"
70- addressBar.validate()
71- compare(addressBar.requestedUrl, "http://192.168.1.1:8000/dummy.html")
72- }
73-
74- function test_unhandled_scheme_no_rewrite() {
75- addressBar.text = "ftp://ubuntu.com"
76- addressBar.validate()
77- compare(addressBar.requestedUrl, "ftp://ubuntu.com")
78- }
79-
80- function test_trim_whitespaces() {
81- addressBar.text = " http://ubuntu.com"
82- addressBar.validate()
83- compare(addressBar.requestedUrl, "http://ubuntu.com")
84- addressBar.text = "http://ubuntu.com "
85- addressBar.validate()
86- compare(addressBar.requestedUrl, "http://ubuntu.com")
87- addressBar.text = " http://ubuntu.com "
88- addressBar.validate()
89- compare(addressBar.requestedUrl, "http://ubuntu.com")
90- }
91-
92- function test_search_url() {
93- addressBar.text = "lorem ipsum dolor sit amet"
94- addressBar.validate()
95- compare(addressBar.requestedUrl.toString().indexOf("https://google.com"), 0)
96- verify(addressBar.requestedUrl.toString().indexOf("q=lorem+ipsum+dolor+sit+amet") > 0)
97- }
98-
99- function test_search_url_single_word() {
100- addressBar.text = "ubuntu"
101- addressBar.validate()
102- compare(addressBar.requestedUrl.toString().indexOf("https://google.com"), 0)
103- verify(addressBar.requestedUrl.toString().indexOf("q=ubuntu") > 0)
104- }
105-
106- function test_search_escape_html_entities() {
107- addressBar.text = "tom & jerry"
108- addressBar.validate()
109- verify(addressBar.requestedUrl.toString().indexOf("q=tom+%26+jerry") > 0)
110- addressBar.text = "a+ rating"
111- addressBar.validate()
112- verify(addressBar.requestedUrl.toString().indexOf("q=a%2B+rating") > 0)
113- addressBar.text = "\"kung fu\""
114- addressBar.validate()
115- verify(addressBar.requestedUrl.toString().indexOf("q=%22kung+fu%22") > 0)
116- addressBar.text = "surfin' usa"
117- addressBar.validate()
118- verify(addressBar.requestedUrl.toString().indexOf("q=surfin%27+usa") > 0)
119- addressBar.text = "to be or not to be?"
120- addressBar.validate()
121- verify(addressBar.requestedUrl.toString().indexOf("q=to+be+or+not+to+be%3F") > 0)
122- }
123-
124- function test_url_uppercase_rewrite() {
125- addressBar.text = "WWW.UBUNTU.COM"
126- addressBar.validate()
127- compare(addressBar.requestedUrl, "http://www.ubuntu.com")
128-
129- addressBar.text = "EN.WIKIPEDIA.ORG/wiki/Ubuntu"
130- addressBar.validate()
131- compare(addressBar.requestedUrl, "http://en.wikipedia.org/wiki/Ubuntu")
132-
133- addressBar.text = "EN.WIKIPEDIA.ORG/wiki/UBUNTU"
134- addressBar.validate()
135- compare(addressBar.requestedUrl, "http://en.wikipedia.org/wiki/UBUNTU")
136- }
137-
138- function test_local_file_no_scheme() {
139- addressBar.text = "/usr/share/doc/ubuntu-online-tour/index.html"
140- addressBar.validate()
141- compare(addressBar.requestedUrl, "file:///usr/share/doc/ubuntu-online-tour/index.html")
142+ function test_no_rewrite_data() {
143+ return [
144+ {url: "file:///usr/share/doc/ubuntu-online-tour/index.html"},
145+ {url: "http://ubuntu.com"},
146+ {url: "https://google.com"},
147+ {url: "ftp://ubuntu.com"},
148+ ]
149+ }
150+
151+ function test_no_rewrite(data) {
152+ addressBar.text = data.url
153+ addressBar.validate()
154+ compare(addressBar.requestedUrl, data.url)
155+ }
156+
157+ function test_add_scheme_data() {
158+ return [
159+ {text: "ubuntu.com", requestedUrl: "http://ubuntu.com"},
160+ {text: "192.168.1.1", requestedUrl: "http://192.168.1.1"},
161+ {text: "192.168.1.1:8000", requestedUrl: "http://192.168.1.1:8000"},
162+ {text: "192.168.1.1:8000/dummy.html", requestedUrl: "http://192.168.1.1:8000/dummy.html"},
163+ {text: "/usr/share/doc/ubuntu-online-tour/index.html", requestedUrl: "file:///usr/share/doc/ubuntu-online-tour/index.html"},
164+ ]
165+ }
166+
167+ function test_add_scheme(data) {
168+ addressBar.text = data.text
169+ addressBar.validate()
170+ compare(addressBar.requestedUrl, data.requestedUrl)
171+ }
172+
173+ function test_trim_whitespaces_data() {
174+ return [
175+ {text: " http://ubuntu.com", requestedUrl: "http://ubuntu.com"},
176+ {text: "http://ubuntu.com ", requestedUrl: "http://ubuntu.com"},
177+ {text: " http://ubuntu.com ", requestedUrl: "http://ubuntu.com"},
178+ ]
179+ }
180+
181+ function test_trim_whitespaces(data) {
182+ addressBar.text = data.text
183+ addressBar.validate()
184+ compare(addressBar.requestedUrl, data.requestedUrl)
185+ }
186+
187+ function test_search_url_data() {
188+ return [
189+ {text: "lorem ipsum dolor sit amet", start: "https://google.com", query: "lorem+ipsum+dolor+sit+amet"},
190+ {text: "ubuntu", start: "https://google.com", query: "ubuntu"},
191+ ]
192+ }
193+
194+ function test_search_url(data) {
195+ addressBar.text = data.text
196+ addressBar.validate()
197+ compare(addressBar.requestedUrl.toString().indexOf(data.start), 0)
198+ verify(addressBar.requestedUrl.toString().indexOf("q=" + data.query) > 0)
199+ }
200+
201+ function test_search_escape_html_entities_data() {
202+ return [
203+ {text: "tom & jerry", escaped: "tom+%26+jerry"},
204+ {text: "a+ rating", escaped: "a%2B+rating"},
205+ {text: "\"kung fu\"", escaped: "%22kung+fu%22"},
206+ {text: "surfin' usa", escaped: "surfin'+usa"},
207+ {text: "to be or not to be?", escaped: "to+be+or+not+to+be%3F"},
208+ {text: "aléatoire", escaped: "aléatoire"},
209+ ]
210+ }
211+
212+ function test_search_escape_html_entities(data) {
213+ addressBar.text = data.text
214+ addressBar.validate()
215+ verify(addressBar.requestedUrl.toString().indexOf("q=" + data.escaped) > 0)
216+ }
217+
218+ function test_url_uppercase_rewrite_data() {
219+ return [
220+ {text: "WWW.UBUNTU.COM", requestedUrl: "http://www.ubuntu.com"},
221+ {text: "EN.WIKIPEDIA.ORG/wiki/Ubuntu", requestedUrl: "http://en.wikipedia.org/wiki/Ubuntu"},
222+ {text: "EN.WIKIPEDIA.ORG/wiki/UBUNTU", requestedUrl: "http://en.wikipedia.org/wiki/UBUNTU"},
223+ ]
224+ }
225+
226+ function test_url_uppercase_rewrite(data) {
227+ addressBar.text = data.text
228+ addressBar.validate()
229+ compare(addressBar.requestedUrl, data.requestedUrl)
230 }
231
232 AddressBar {

Subscribers

People subscribed via source and target branches

to status/vote changes: