Merge pull request #59 from Worble/#36_sanitize_search_inputs

encodeUriComponent search query before adding to router path
This commit is contained in:
Preston 2020-08-04 22:12:42 -04:00 committed by GitHub
commit 30b4392a77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 32 deletions

View File

@ -10,14 +10,14 @@ export default Vue.extend({
name: 'TopNav', name: 'TopNav',
components: { components: {
FtInput, FtInput,
FtSearchFilters FtSearchFilters,
}, },
data: () => { data: () => {
return { return {
component: this, component: this,
windowWidth: 0, windowWidth: 0,
showFilters: false, showFilters: false,
searchSuggestionsDataList: [] searchSuggestionsDataList: [],
} }
}, },
computed: { computed: {
@ -82,23 +82,19 @@ export default Vue.extend({
this.$store.dispatch('getVideoIdFromUrl', query).then((result) => { this.$store.dispatch('getVideoIdFromUrl', query).then((result) => {
if (result) { if (result) {
this.$router.push( this.$router.push({
{
path: `/watch/${result}`, path: `/watch/${result}`,
} })
)
} else { } else {
router.push( router.push({
{ path: `/search/${encodeURIComponent(query)}`,
path: `/search/${query}`,
query: { query: {
sortBy: this.searchSettings.sortBy, sortBy: this.searchSettings.sortBy,
time: this.searchSettings.time, time: this.searchSettings.time,
type: this.searchSettings.type, type: this.searchSettings.type,
duration: this.searchSettings.duration duration: this.searchSettings.duration,
} },
} })
)
} }
}) })
@ -143,16 +139,21 @@ export default Vue.extend({
resource: 'search/suggestions', resource: 'search/suggestions',
id: '', id: '',
params: { params: {
q: query q: query,
} },
} }
this.$store.dispatch('invidiousAPICall', searchPayload).then((results) => { this.$store
.dispatch('invidiousAPICall', searchPayload)
.then((results) => {
this.searchSuggestionsDataList = results.suggestions this.searchSuggestionsDataList = results.suggestions
}).error((err) => { })
.error((err) => {
console.log(err) console.log(err)
if (this.backendFallback) { if (this.backendFallback) {
console.log('Error gettings search suggestions. Falling back to Local API') console.log(
'Error gettings search suggestions. Falling back to Local API'
)
this.getSearchSuggestionsLocal(query) this.getSearchSuggestionsLocal(query)
} }
}) })
@ -180,6 +181,6 @@ export default Vue.extend({
toggleSideNav: function () { toggleSideNav: function () {
this.$store.commit('toggleSideNav') this.$store.commit('toggleSideNav')
} },
} },
}) })