Whitespace is not trimmed from the end of query strings (#1263)

* fixed whitespace not trimmed query string
* fixed whitespace trimming on backend
* added query trim tests and fixed double space
This commit is contained in:
julien0221
2021-04-13 01:32:52 +01:00
committed by GitHub
parent f5dc654f6b
commit 6a4421f8e1
5 changed files with 67 additions and 6 deletions

View File

@@ -1164,7 +1164,7 @@ func TestSceneQuerySorting(t *testing.T) {
lastScene := scenes[len(scenes)-1]
assert.Equal(t, sceneIDs[0], firstScene.ID)
assert.Equal(t, sceneIDs[len(sceneIDs)-1], lastScene.ID)
assert.Equal(t, sceneIDs[sceneIdxWithSpacedName], lastScene.ID)
// sort in descending order
direction = models.SortDirectionEnumDesc
@@ -1173,7 +1173,7 @@ func TestSceneQuerySorting(t *testing.T) {
firstScene = scenes[0]
lastScene = scenes[len(scenes)-1]
assert.Equal(t, sceneIDs[len(sceneIDs)-1], firstScene.ID)
assert.Equal(t, sceneIDs[sceneIdxWithSpacedName], firstScene.ID)
assert.Equal(t, sceneIDs[0], lastScene.ID)
return nil
@@ -1519,6 +1519,49 @@ func TestSceneStashIDs(t *testing.T) {
}
}
func TestSceneQueryQTrim(t *testing.T) {
if err := withTxn(func(r models.Repository) error {
qb := r.Scene()
expectedID := sceneIDs[sceneIdxWithSpacedName]
type test struct {
query string
id int
count int
}
tests := []test{
{query: " zzz yyy ", id: expectedID, count: 1},
{query: " \"zzz yyy xxx\" ", id: expectedID, count: 1},
{query: "zzz", id: expectedID, count: 1},
{query: "\" zzz yyy \"", count: 0},
{query: "\"zzz yyy\"", count: 0},
{query: "\" zzz yyy\"", count: 0},
{query: "\"zzz yyy \"", count: 0},
}
for _, tst := range tests {
f := models.FindFilterType{
Q: &tst.query,
}
scenes := queryScene(t, qb, nil, &f)
assert.Len(t, scenes, tst.count)
if len(scenes) > 0 {
assert.Equal(t, tst.id, scenes[0].ID)
}
}
findFilter := models.FindFilterType{}
scenes := queryScene(t, qb, nil, &findFilter)
assert.NotEqual(t, 0, len(scenes))
return nil
}); err != nil {
t.Error(err.Error())
}
}
// TODO Update
// TODO IncrementOCounter
// TODO DecrementOCounter