Skip to content

Commit b1a2bdb

Browse files
author
Mike Taylor
authored
Merge pull request #1518 from /issues/1515
Fixes #1515 - fixed encoding param
2 parents e02eccb + 73d6c54 commit b1a2bdb

File tree

3 files changed

+112
-41
lines changed

3 files changed

+112
-41
lines changed

tests/functional/issue-list-non-auth.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -463,34 +463,6 @@ define(
463463
})
464464
.end()
465465
);
466-
},
467-
468-
"Results are loaded from the query params": function() {
469-
var params = "?q=vladvlad";
470-
return FunctionalHelpers.openPage(
471-
this,
472-
url("/issues", params),
473-
".js-IssueList:nth-of-type(1)"
474-
)
475-
.findByCssSelector(".wc-IssueList:nth-of-type(1) a")
476-
.getVisibleText()
477-
.then(function(text) {
478-
assert.include(
479-
text,
480-
"vladvlad",
481-
"The search query results show up on the page."
482-
);
483-
})
484-
.end()
485-
.getCurrentUrl()
486-
.then(function(currUrl) {
487-
assert.include(
488-
currUrl,
489-
"q=vladvlad",
490-
"Our params didn't go anywhere."
491-
);
492-
})
493-
.end();
494466
}
495467
});
496468
}

tests/functional/search-non-auth.js

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ define(
88
"intern!object",
99
"intern/chai!assert",
1010
"require",
11-
"tests/functional/lib/helpers"
11+
"tests/functional/lib/helpers",
12+
"intern/dojo/node!leadfoot/keys"
1213
],
13-
function(intern, registerSuite, assert, require, FunctionalHelpers) {
14+
function(intern, registerSuite, assert, require, FunctionalHelpers, keys) {
1415
"use strict";
1516
var url = function(path, params) {
1617
var base = intern.config.siteRoot + path;
@@ -128,6 +129,82 @@ define(
128129
);
129130
})
130131
.end();
132+
},
133+
134+
"Search with a dash works": function() {
135+
// load up a garbage search, so we can more easily detect when
136+
// the search values we want are loaded.
137+
var searchParam = "?q=jfdkjfkdjfkdjfdkjfkd";
138+
return FunctionalHelpers.openPage(
139+
this,
140+
url("/issues", searchParam),
141+
".wc-SearchIssue-noResults-title"
142+
)
143+
.findByCssSelector("#js-SearchForm-input")
144+
.clearValue()
145+
.click()
146+
.type("label:status-tacos")
147+
.type(keys.ENTER)
148+
.end()
149+
.findDisplayedByCssSelector(
150+
".wc-IssueList:first-of-type .js-Issue-label"
151+
)
152+
.getVisibleText()
153+
.then(function(text) {
154+
assert.include(
155+
text,
156+
"tacos",
157+
"The label:status-tacos search worked."
158+
);
159+
})
160+
.end();
161+
},
162+
163+
"Search input is loaded from q param (with dashes)": function() {
164+
// load up a garbage search, so we can more easily detect when
165+
// the search values we want are loaded.
166+
var searchParam = "?q=one:two-three";
167+
return FunctionalHelpers.openPage(
168+
this,
169+
url("/issues", searchParam),
170+
".wc-SearchIssue-noResults-title"
171+
)
172+
.findByCssSelector("#js-SearchForm-input")
173+
.getProperty("value")
174+
.then(function(text) {
175+
assert.include(
176+
text,
177+
"one:two-three",
178+
"The q param populated the search input."
179+
);
180+
})
181+
.end();
182+
},
183+
184+
"Empty search input removes q param": function() {
185+
// load up a garbage search, so we can more easily detect when
186+
// the search values we want are loaded.
187+
var searchParam = "?q=fffffff";
188+
return FunctionalHelpers.openPage(
189+
this,
190+
url("/issues", searchParam),
191+
".js-SearchForm"
192+
)
193+
.findByCssSelector("#js-SearchForm-input")
194+
.clearValue()
195+
.click()
196+
.type("")
197+
.type(keys.ENTER)
198+
.sleep(1000)
199+
.getCurrentUrl()
200+
.then(function(currUrl) {
201+
assert.notInclude(
202+
currUrl,
203+
"q=fffffff",
204+
"old search param was removed"
205+
);
206+
})
207+
.end();
131208
}
132209
});
133210
}

webcompat/static/js/lib/issue-list.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ issueList.SearchView = Backbone.View.extend({
190190
initialize: function() {
191191
issueList.events.on("search:update", _.bind(this.updateSearchQuery, this));
192192
issueList.events.on("search:clear", _.bind(this.clearSearchBox, this));
193+
issueList.events.on("search:current", _.bind(this.currentSearch, this));
193194
},
194195
template: _.template($("#issuelist-search-tmpl").html()),
195196
render: function(cb) {
@@ -207,6 +208,9 @@ issueList.SearchView = Backbone.View.extend({
207208
updateSearchQuery: function(data) {
208209
this.input.val(data);
209210
},
211+
currentSearch: function(data) {
212+
this._currentSearch = data;
213+
},
210214
_isEmpty: true,
211215
_currentSearch: null,
212216
searchIfNotEmpty: _.debounce(function(e) {
@@ -218,8 +222,8 @@ issueList.SearchView = Backbone.View.extend({
218222
// don't search if nothing has changed
219223
// (or user just added whitespace)
220224
if ($.trim(searchValue) !== this._currentSearch) {
221-
this._currentSearch = $.trim(searchValue);
222-
this.doSearch(this._currentSearch);
225+
this.currentSearch($.trim(searchValue));
226+
this.doSearch($.trim(searchValue));
223227
// clear any filters that have been set.
224228
issueList.events.trigger("filter:clear", { removeQ: false });
225229
}
@@ -228,9 +232,10 @@ issueList.SearchView = Backbone.View.extend({
228232
// if it's empty and the user searches, show the default results
229233
// (but only once)
230234
if (!searchValue.length && this._currentSearch !== "") {
231-
this._currentSearch = "";
235+
this.doSearch("");
236+
this.currentSearch("");
237+
issueList.events.trigger("filter:clear", { removeQ: true });
232238
this._isEmpty = true;
233-
issueList.events.trigger("issues:update");
234239
}
235240
}, 350),
236241
doSearch: _.throttle(function(value) {
@@ -336,14 +341,22 @@ issueList.IssueView = Backbone.View.extend(
336341
// There are some params in the URL
337342
if (urlParams.length !== 0) {
338343
queryMatch = urlParams.match(this._searchRegex);
344+
if (queryMatch) {
345+
_.delay(function() {
346+
issueList.events.trigger(
347+
"search:update",
348+
decodeURIComponent(queryMatch[1])
349+
);
350+
issueList.events.trigger(
351+
"search:current",
352+
decodeURIComponent(queryMatch[1])
353+
);
354+
}, 0);
355+
}
339356
if (!this._isLoggedIn && queryMatch) {
340357
// We're dealing with an un-authed user, with a q param.
341358
this.doGitHubSearch(urlParams);
342359
this.updateModelParams(urlParams);
343-
_.delay(function() {
344-
// TODO: update search input from query param for authed users.
345-
issueList.events.trigger("search:update", queryMatch[1]);
346-
}, 0);
347360
} else if (
348361
(category = window.location.search.match(this._filterRegex))
349362
) {
@@ -473,13 +486,22 @@ issueList.IssueView = Backbone.View.extend(
473486
this.issues.setURLState("/api/issues/search", paramsCopy);
474487
}
475488
} else if (_.contains(issuesAPICategories, category)) {
476-
this.issues.setURLState("/api/issues/category/" + category, params);
489+
this.issues.setURLState(
490+
"/api/issues/category/" + category,
491+
this.removeParamQuery(params)
492+
);
477493
} else {
478-
this.issues.setURLState("/api/issues", params);
494+
this.issues.setURLState("/api/issues", this.removeParamQuery(params));
479495
}
480496

481497
this.fetchAndRenderIssues();
482498
},
499+
removeParamQuery: function(params) {
500+
if (params && params.q) {
501+
delete params.q;
502+
}
503+
return params;
504+
},
483505
addParamsToModel: function(paramsArray) {
484506
// this method just puts the params in the model's params property.
485507
// paramsArray is an array of param 'key=value' string pairs
@@ -489,7 +511,7 @@ issueList.IssueView = Backbone.View.extend(
489511
var kvArray = param.split("=");
490512
var key = kvArray[0];
491513
var value = kvArray[1];
492-
this.issues.params[key] = value;
514+
this.issues.params[key] = decodeURIComponent(value);
493515
}, this)
494516
);
495517
},

0 commit comments

Comments
 (0)