Fix search query parser (unicode)
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
b74c32b5f2
commit
84bf4700ec
7 changed files with 26 additions and 12 deletions
|
@ -1,5 +1,7 @@
|
|||
<template>
|
||||
<v-form ref="form" autocomplete="off" class="p-photo-search p-album-photo-search" lazy-validation @submit.prevent="filterChange" dense>
|
||||
<v-form lazy-validation dense
|
||||
ref="form" autocomplete="off" class="p-photo-search p-album-photo-search" accept-charset="UTF-8"
|
||||
@submit.prevent="filterChange">
|
||||
<v-toolbar flat color="secondary">
|
||||
<v-text-field class="pt-3 pr-3 p-search-field"
|
||||
browser-autocomplete="off"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<template>
|
||||
<v-form ref="form" autocomplete="off" class="p-photo-search" lazy-validation @submit.prevent="filterChange" dense>
|
||||
<v-form lazy-validation dense
|
||||
ref="form" autocomplete="off" class="p-photo-search" accept-charset="UTF-8"
|
||||
@submit.prevent="filterChange">
|
||||
<v-toolbar flat color="secondary">
|
||||
<v-text-field class="pt-3 pr-3 p-search-field"
|
||||
browser-autocomplete="off"
|
||||
|
|
|
@ -113,7 +113,7 @@
|
|||
const photo = this.results[index];
|
||||
|
||||
if (photo.PhotoLat && photo.PhotoLong) {
|
||||
this.$router.push({name: "places", query: {lat: photo.PhotoLat, long: photo.PhotoLong}});
|
||||
this.$router.push({name: "places", query: {lat: String(photo.PhotoLat), long: String(photo.PhotoLong)}});
|
||||
} else if (photo.LocName) {
|
||||
this.$router.push({name: "places", query: {q: photo.LocName}});
|
||||
} else if (photo.LocCity) {
|
||||
|
@ -165,6 +165,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (JSON.stringify(this.$route.query) === JSON.stringify(query)) {
|
||||
return
|
||||
}
|
||||
|
||||
this.$router.replace({query: query});
|
||||
},
|
||||
searchParams() {
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
const photo = this.results[index];
|
||||
|
||||
if (photo.PhotoLat && photo.PhotoLong) {
|
||||
this.$router.push({name: "places", query: {lat: photo.PhotoLat, long: photo.PhotoLong}});
|
||||
this.$router.push({name: "places", query: {lat: String(photo.PhotoLat), long: String(photo.PhotoLong)}});
|
||||
} else if (photo.LocName) {
|
||||
this.$router.push({name: "places", query: {q: photo.LocName}});
|
||||
} else if (photo.LocCity) {
|
||||
|
@ -157,6 +157,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (JSON.stringify(this.$route.query) === JSON.stringify(query)) {
|
||||
return
|
||||
}
|
||||
|
||||
this.$router.replace({query: query});
|
||||
},
|
||||
searchParams() {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<template>
|
||||
<div class="p-tab p-tab-general">
|
||||
<v-container fluid>
|
||||
<v-form ref="form" class="p-form-settings" lazy-validation @submit.prevent="save" dense>
|
||||
<v-form lazy-validation dense
|
||||
ref="form" class="p-form-settings" accept-charset="UTF-8"
|
||||
@submit.prevent="save">
|
||||
<v-layout wrap align-center>
|
||||
<v-flex xs12 sm6 class="pr-3">
|
||||
<v-select
|
||||
|
|
|
@ -41,6 +41,7 @@ func GetPhotos(router *gin.RouterGroup, conf *config.Config) {
|
|||
}
|
||||
|
||||
result, err := search.Photos(f)
|
||||
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(400, gin.H{"error": util.UcFirst(err.Error())})
|
||||
return
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package form
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
@ -48,7 +47,7 @@ type PhotoSearch struct {
|
|||
}
|
||||
|
||||
func (f *PhotoSearch) ParseQueryString() (result error) {
|
||||
var key, value []byte
|
||||
var key, value []rune
|
||||
var escaped, isKeyValue bool
|
||||
|
||||
query := f.Query
|
||||
|
@ -62,9 +61,9 @@ func (f *PhotoSearch) ParseQueryString() (result error) {
|
|||
for _, char := range query {
|
||||
if unicode.IsSpace(char) && !escaped {
|
||||
if isKeyValue {
|
||||
fieldName := string(bytes.Title(bytes.ToLower(key)))
|
||||
fieldName := strings.Title(string(key))
|
||||
field := formValues.FieldByName(fieldName)
|
||||
stringValue := string(bytes.ToLower(value))
|
||||
stringValue := string(value)
|
||||
|
||||
if field.CanSet() {
|
||||
switch field.Interface().(type) {
|
||||
|
@ -109,7 +108,7 @@ func (f *PhotoSearch) ParseQueryString() (result error) {
|
|||
result = fmt.Errorf("unknown filter: %s", fieldName)
|
||||
}
|
||||
} else {
|
||||
f.Query = string(bytes.ToLower(key))
|
||||
f.Query = string(key)
|
||||
}
|
||||
|
||||
escaped = false
|
||||
|
@ -121,9 +120,9 @@ func (f *PhotoSearch) ParseQueryString() (result error) {
|
|||
} else if char == '"' {
|
||||
escaped = !escaped
|
||||
} else if isKeyValue {
|
||||
value = append(value, byte(char))
|
||||
value = append(value, unicode.ToLower(char))
|
||||
} else {
|
||||
key = append(key, byte(char))
|
||||
key = append(key, unicode.ToLower(char))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue