Merge pull request #1175 from rschamp/bugfix/1153

URI-encode search string on form submit
This commit is contained in:
Ray Schamp 2017-02-14 19:42:31 -05:00 committed by GitHub
commit 5697a87cb7
2 changed files with 17 additions and 19 deletions

View file

@ -171,7 +171,7 @@ var Navigation = React.createClass({
this.closeRegistration();
},
onSearchSubmit: function (formData) {
window.location.href = '/search/projects?q=' + formData.q;
window.location.href = '/search/projects?q=' + encodeURIComponent(formData.q);
},
render: function () {
var classes = classNames({

View file

@ -21,13 +21,25 @@ require('./search.scss');
var Search = injectIntl(React.createClass({
type: 'Search',
getDefaultProps: function () {
var query = window.location.search;
var pathname = window.location.pathname.toLowerCase();
if (pathname[pathname.length - 1] === '/') {
pathname = pathname.substring(0, pathname.length - 1);
}
var start = pathname.lastIndexOf('/');
var type = pathname.substring(start + 1, pathname.length);
return {
tab: type,
loadNumber: 16
};
},
getInitialState: function () {
return {
loaded: [],
offset: 0
};
},
componentDidMount: function () {
var query = window.location.search;
var q = query.lastIndexOf('q=');
var term = '';
if (q !== -1) {
@ -40,22 +52,8 @@ var Search = injectIntl(React.createClass({
term = term.substring(0, term.indexOf('&'));
}
term = term.split('+').join(' ');
return {
tab: type,
searchTerm: term,
loadNumber: 16
};
},
getInitialState: function () {
return {
loaded: [],
offset: 0
};
},
componentDidMount: function () {
this.getSearchMore();
this.props.dispatch(navigationActions.setSearchTerm(this.props.searchTerm));
this.props.dispatch(navigationActions.setSearchTerm(decodeURI(term)));
},
getSearchMore: function () {
var termText = '';
@ -113,7 +111,7 @@ var Search = injectIntl(React.createClass({
<Input type="text"
aria-label={formatMessage({id: 'general.search'})}
placeholder={formatMessage({id: 'general.search'})}
value={decodeURI(this.props.searchTerm)}
value={this.props.searchTerm}
name="q" />
</Form>
</div>
@ -143,7 +141,7 @@ var Search = injectIntl(React.createClass({
var mapStateToProps = function (state) {
return {
navigation: state.searchTerm
searchTerm: state.navigation
};
};