mirror of
https://github.com/xiaoxinpro/nginx-proxy-manager-zh.git
synced 2025-03-14 17:48:14 -04:00
Quote filter fields
This commit is contained in:
parent
9a2e5c92d5
commit
e78dd069f1
@ -122,12 +122,12 @@ func (s *testsuite) TestList() {
|
|||||||
defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||||
|
|
||||||
s.mock.
|
s.mock.
|
||||||
ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "certificate_authority" WHERE name LIKE $1 AND "certificate_authority"."is_deleted" = $2`)).
|
ExpectQuery(regexp.QuoteMeta("SELECT count(*) FROM \"certificate_authority\" WHERE `certificate_authority`.`name` LIKE $1 AND \"certificate_authority\".\"is_deleted\" = $2")).
|
||||||
WithArgs("%test%", 0).
|
WithArgs("%test%", 0).
|
||||||
WillReturnRows(s.listCountRows)
|
WillReturnRows(s.listCountRows)
|
||||||
|
|
||||||
s.mock.
|
s.mock.
|
||||||
ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "certificate_authority" WHERE name LIKE $1 AND "certificate_authority"."is_deleted" = $2 ORDER BY name asc LIMIT $3`)).
|
ExpectQuery(regexp.QuoteMeta("SELECT * FROM \"certificate_authority\" WHERE `certificate_authority`.`name` LIKE $1 AND \"certificate_authority\".\"is_deleted\" = $2 ORDER BY name asc LIMIT $3")).
|
||||||
WithArgs("%test%", 0, 8).
|
WithArgs("%test%", 0, 8).
|
||||||
WillReturnRows(s.listRows)
|
WillReturnRows(s.listRows)
|
||||||
|
|
||||||
|
@ -204,12 +204,12 @@ func (s *testsuite) TestList() {
|
|||||||
defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||||
|
|
||||||
s.mock.
|
s.mock.
|
||||||
ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "dns_provider" WHERE acmesh_name LIKE $1 AND "dns_provider"."is_deleted" = $2`)).
|
ExpectQuery(regexp.QuoteMeta("SELECT count(*) FROM \"dns_provider\" WHERE `dns_provider`.`acmesh_name` LIKE $1 AND \"dns_provider\".\"is_deleted\" = $2")).
|
||||||
WithArgs("dns%", 0).
|
WithArgs("dns%", 0).
|
||||||
WillReturnRows(s.listCountRows)
|
WillReturnRows(s.listCountRows)
|
||||||
|
|
||||||
s.mock.
|
s.mock.
|
||||||
ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "dns_provider" WHERE acmesh_name LIKE $1 AND "dns_provider"."is_deleted" = $2 ORDER BY name asc LIMIT $3`)).
|
ExpectQuery(regexp.QuoteMeta("SELECT * FROM \"dns_provider\" WHERE `dns_provider`.`acmesh_name` LIKE $1 AND \"dns_provider\".\"is_deleted\" = $2 ORDER BY name asc LIMIT $3")).
|
||||||
WithArgs("dns%", 0, 8).
|
WithArgs("dns%", 0, 8).
|
||||||
WillReturnRows(s.listRows)
|
WillReturnRows(s.listRows)
|
||||||
|
|
||||||
|
@ -307,12 +307,12 @@ func (s *testsuite) TestList() {
|
|||||||
defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||||
|
|
||||||
s.mock.
|
s.mock.
|
||||||
ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "user" WHERE name LIKE $1 AND "user"."is_deleted" = $2`)).
|
ExpectQuery(regexp.QuoteMeta("SELECT count(*) FROM \"user\" WHERE `user`.`name` LIKE $1 AND \"user\".\"is_deleted\" = $2")).
|
||||||
WithArgs("%jon%", 0).
|
WithArgs("%jon%", 0).
|
||||||
WillReturnRows(s.listCountRows)
|
WillReturnRows(s.listCountRows)
|
||||||
|
|
||||||
s.mock.
|
s.mock.
|
||||||
ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "user" WHERE name LIKE $1 AND "user"."is_deleted" = $2 ORDER BY name asc LIMIT $3`)).
|
ExpectQuery(regexp.QuoteMeta("SELECT * FROM \"user\" WHERE `user`.`name` LIKE $1 AND \"user\".\"is_deleted\" = $2 ORDER BY name asc LIMIT $3")).
|
||||||
WithArgs("%jon%", 0, 8).
|
WithArgs("%jon%", 0, 8).
|
||||||
WillReturnRows(s.listRows)
|
WillReturnRows(s.listRows)
|
||||||
|
|
||||||
|
@ -86,7 +86,6 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
|
|||||||
// DeleteAll will do just that, and should only be used for testing purposes.
|
// DeleteAll will do just that, and should only be used for testing purposes.
|
||||||
func DeleteAll() error {
|
func DeleteAll() error {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
// nolint errcheck
|
|
||||||
result := db.Exec(fmt.Sprintf(`DELETE FROM %s WHERE is_system = ?`, database.QuoteTableName("user")), false)
|
result := db.Exec(fmt.Sprintf(`DELETE FROM %s WHERE is_system = ?`, database.QuoteTableName("user")), false)
|
||||||
return result.Error
|
return result.Error
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"npm/internal/database"
|
||||||
"npm/internal/logger"
|
"npm/internal/logger"
|
||||||
"npm/internal/model"
|
"npm/internal/model"
|
||||||
"npm/internal/util"
|
"npm/internal/util"
|
||||||
@ -33,8 +34,8 @@ func GetFilterMap(m interface{}, globalTablePrefix string) map[string]model.Filt
|
|||||||
n := tableNameFunc.Func.Call([]reflect.Value{v})
|
n := tableNameFunc.Func.Call([]reflect.Value{v})
|
||||||
if len(n) > 0 {
|
if len(n) > 0 {
|
||||||
globalTablePrefix = fmt.Sprintf(
|
globalTablePrefix = fmt.Sprintf(
|
||||||
`"%s".`,
|
`%s.`,
|
||||||
n[0].String(),
|
database.QuoteTableName(n[0].String()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,10 +83,10 @@ func GetFilterMap(m interface{}, globalTablePrefix string) map[string]model.Filt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// db can have many parts, we need to pull out the "column:value" part
|
// db can have many parts, we need to pull out the "column:value" part
|
||||||
f.Field = field.Name
|
f.Field = database.QuoteTableName(field.Name)
|
||||||
r := regexp.MustCompile(`(?:^|;)column:([^;|$]+)(?:$|;)`)
|
r := regexp.MustCompile(`(?:^|;)column:([^;|$]+)(?:$|;)`)
|
||||||
if matches := r.FindStringSubmatch(dbTag); len(matches) > 1 {
|
if matches := r.FindStringSubmatch(dbTag); len(matches) > 1 {
|
||||||
f.Field = fmt.Sprintf("%s%s", tablePrefix, matches[1])
|
f.Field = fmt.Sprintf("%s%s", tablePrefix, database.QuoteTableName(matches[1]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filterMap[parts[0]] = f
|
filterMap[parts[0]] = f
|
||||||
|
@ -14,6 +14,7 @@ if [[ -n "$INCOMPLETE_COMMENTS" ]]; then
|
|||||||
# RESULT=1
|
# RESULT=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo -e "${YELLOW}golangci-lint ...${RESET}"
|
||||||
if ! golangci-lint run -E goimports ./...; then
|
if ! golangci-lint run -E goimports ./...; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user