Skip to content

Commit af2a258

Browse files
committed
chore(test): add edge case tests for user settings shortcuts and JSON fields
1 parent dc7ec8a commit af2a258

File tree

5 files changed

+570
-244
lines changed

5 files changed

+570
-244
lines changed

plugin/filter/render.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ func (r *renderer) jsonBoolPredicate(field Field) (string, error) {
564564
case DialectSQLite:
565565
return fmt.Sprintf("%s IS TRUE", expr), nil
566566
case DialectMySQL:
567-
return fmt.Sprintf("%s = CAST('true' AS JSON)", expr), nil
567+
return fmt.Sprintf("COALESCE(%s, CAST('false' AS JSON)) = CAST('true' AS JSON)", expr), nil
568568
case DialectPostgres:
569569
return fmt.Sprintf("(%s)::boolean IS TRUE", expr), nil
570570
default:

store/test/instance_setting_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,49 @@ func TestInstanceSettingListAll(t *testing.T) {
254254

255255
ts.Close()
256256
}
257+
258+
func TestInstanceSettingEdgeCases(t *testing.T) {
259+
t.Parallel()
260+
ctx := context.Background()
261+
ts := NewTestingStore(ctx, t)
262+
263+
// Case 1: General Setting with special characters and Unicode
264+
specialScript := `<script>alert("你好"); var x = 'test\'s';</script>`
265+
specialStyle := `body { font-family: "Noto Sans SC", sans-serif; content: "\u2764"; }`
266+
_, err := ts.UpsertInstanceSetting(ctx, &storepb.InstanceSetting{
267+
Key: storepb.InstanceSettingKey_GENERAL,
268+
Value: &storepb.InstanceSetting_GeneralSetting{
269+
GeneralSetting: &storepb.InstanceGeneralSetting{
270+
AdditionalScript: specialScript,
271+
AdditionalStyle: specialStyle,
272+
},
273+
},
274+
})
275+
require.NoError(t, err)
276+
277+
generalSetting, err := ts.GetInstanceGeneralSetting(ctx)
278+
require.NoError(t, err)
279+
require.Equal(t, specialScript, generalSetting.AdditionalScript)
280+
require.Equal(t, specialStyle, generalSetting.AdditionalStyle)
281+
282+
// Case 2: Memo Related Setting with Unicode reactions
283+
unicodeReactions := []string{"🐱", "🐶", "🦊", "🦄"}
284+
_, err = ts.UpsertInstanceSetting(ctx, &storepb.InstanceSetting{
285+
Key: storepb.InstanceSettingKey_MEMO_RELATED,
286+
Value: &storepb.InstanceSetting_MemoRelatedSetting{
287+
MemoRelatedSetting: &storepb.InstanceMemoRelatedSetting{
288+
ContentLengthLimit: 1000,
289+
Reactions: unicodeReactions,
290+
},
291+
},
292+
})
293+
require.NoError(t, err)
294+
295+
memoSetting, err := ts.GetInstanceMemoRelatedSetting(ctx)
296+
require.NoError(t, err)
297+
require.Equal(t, unicodeReactions, memoSetting.Reactions)
298+
299+
ts.Close()
300+
}
301+
302+

store/test/memo_filter_comprehension_test.go

Lines changed: 0 additions & 243 deletions
This file was deleted.

0 commit comments

Comments
 (0)