Merge pull request #10 from mattn/escape-percent
Some checks failed
build cli / make-release (push) Has been cancelled
build cli / build-linux (push) Has been cancelled

escape %
This commit is contained in:
mattn
2024-01-30 14:46:36 +09:00
committed by GitHub
3 changed files with 24 additions and 16 deletions

View File

@@ -120,22 +120,26 @@ func (b MySQLBackend) queryEventsSql(filter nostr.Filter, doCount bool) (string,
// we use a very bad implementation in which we only check the tag values and
// ignore the tag names
for _, tagValue := range tagQuery {
params = append(params, "%"+tagValue+"%")
conditions = append(conditions, "tags LIKE ?")
conditions = append(conditions, `tags LIKE ?`)
params = append(params, `%`+strings.ReplaceAll(tagValue, `%`, `\%`)+`%`)
}
if filter.Since != nil {
conditions = append(conditions, "created_at >= ?")
conditions = append(conditions, `created_at >= ?`)
params = append(params, filter.Since)
}
if filter.Until != nil {
conditions = append(conditions, "created_at <= ?")
conditions = append(conditions, `created_at <= ?`)
params = append(params, filter.Until)
}
if filter.Search != "" {
conditions = append(conditions, `content LIKE ?`)
params = append(params, `%`+strings.ReplaceAll(filter.Search, `%`, `\%`)+`%`)
}
if len(conditions) == 0 {
// fallback
conditions = append(conditions, "true")
conditions = append(conditions, `true`)
}
if filter.Limit < 1 || filter.Limit > b.QueryLimit {

View File

@@ -119,21 +119,25 @@ func (b PostgresBackend) queryEventsSql(filter nostr.Filter, doCount bool) (stri
params = append(params, tagValue)
}
conditions = append(conditions, "tagvalues && ARRAY["+makePlaceHolders(len(tagQuery))+"]")
conditions = append(conditions, `tagvalues && ARRAY[`+makePlaceHolders(len(tagQuery))+`]`)
}
if filter.Since != nil {
conditions = append(conditions, "created_at >= ?")
conditions = append(conditions, `created_at >= ?`)
params = append(params, filter.Since)
}
if filter.Until != nil {
conditions = append(conditions, "created_at <= ?")
conditions = append(conditions, `created_at <= ?`)
params = append(params, filter.Until)
}
if filter.Search != "" {
conditions = append(conditions, `content LIKE ?`)
params = append(params, `%`+strings.ReplaceAll(filter.Search, `%`, `\%`)+`%`)
}
if len(conditions) == 0 {
// fallback
conditions = append(conditions, "true")
conditions = append(conditions, `true`)
}
if filter.Limit < 1 || filter.Limit > b.QueryLimit {

View File

@@ -117,26 +117,26 @@ func (b SQLite3Backend) queryEventsSql(filter nostr.Filter, doCount bool) (strin
// we use a very bad implementation in which we only check the tag values and
// ignore the tag names
for _, tagValue := range tagQuery {
params = append(params, "%"+tagValue+"%")
conditions = append(conditions, "tags LIKE ?")
conditions = append(conditions, `tags LIKE ? ESCAPE '\'`)
params = append(params, `%`+strings.ReplaceAll(tagValue, `%`, `\%`)+`%`)
}
if filter.Since != nil {
conditions = append(conditions, "created_at >= ?")
conditions = append(conditions, `created_at >= ?`)
params = append(params, filter.Since)
}
if filter.Until != nil {
conditions = append(conditions, "created_at <= ?")
conditions = append(conditions, `created_at <= ?`)
params = append(params, filter.Until)
}
if filter.Search != "" {
conditions = append(conditions, "content LIKE ?")
params = append(params, "%"+filter.Search+"%")
conditions = append(conditions, `content LIKE ? ESCAPE '\'`)
params = append(params, `%`+strings.ReplaceAll(filter.Search, `%`, `\%`)+`%`)
}
if len(conditions) == 0 {
// fallback
conditions = append(conditions, "true")
conditions = append(conditions, `true`)
}
if filter.Limit < 1 || filter.Limit > b.QueryLimit {