mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-03-25 12:20:24 -04:00
Fix gh-1934: Search bar special chars (#2075)
* Fixed Issue 1934 The text was encoded once already by the search bar. That means we need to decode it twice in order to decode special characters. * Rewrote search query parsing
This commit is contained in:
parent
337a9e2f30
commit
a94b9d6c84
1 changed files with 15 additions and 6 deletions
|
@ -57,12 +57,21 @@ class Search extends React.Component {
|
|||
|
||||
}
|
||||
componentDidMount () {
|
||||
const query = window.location.search;
|
||||
const q = query.lastIndexOf('q=');
|
||||
let term = '';
|
||||
if (q !== -1) {
|
||||
term = query.substring(q + 2, query.length).toLowerCase();
|
||||
}
|
||||
const query = decodeURIComponent(window.location.search);
|
||||
let term = query;
|
||||
|
||||
const stripQueryValue = function (queryTerm) {
|
||||
const queryIndex = query.indexOf('q=');
|
||||
if (queryIndex !== -1) {
|
||||
queryTerm = query.substring(queryIndex + 2, query.length).toLowerCase();
|
||||
}
|
||||
return queryTerm;
|
||||
};
|
||||
// Strip off the initial "?q="
|
||||
term = stripQueryValue(term);
|
||||
// Strip off user entered "?q="
|
||||
term = stripQueryValue(term);
|
||||
|
||||
while (term.indexOf('/') > -1) {
|
||||
term = term.substring(0, term.indexOf('/'));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue