mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-29 07:01:32 +00:00
Fix pq: invalid input syntax for integer
when trying to get a numeric localpart (#2505)
* Match at least once * Add the test
This commit is contained in:
parent
9f8b3136b2
commit
beed39a8f4
@ -65,7 +65,7 @@ const selectPasswordHashSQL = "" +
|
|||||||
"SELECT password_hash FROM account_accounts WHERE localpart = $1 AND is_deactivated = FALSE"
|
"SELECT password_hash FROM account_accounts WHERE localpart = $1 AND is_deactivated = FALSE"
|
||||||
|
|
||||||
const selectNewNumericLocalpartSQL = "" +
|
const selectNewNumericLocalpartSQL = "" +
|
||||||
"SELECT COALESCE(MAX(localpart::integer), 0) FROM account_accounts WHERE localpart ~ '^[0-9]*$'"
|
"SELECT COALESCE(MAX(localpart::integer), 0) FROM account_accounts WHERE localpart ~ '^[0-9]{1,}$'"
|
||||||
|
|
||||||
type accountsStatements struct {
|
type accountsStatements struct {
|
||||||
insertAccountStmt *sql.Stmt
|
insertAccountStmt *sql.Stmt
|
||||||
|
@ -124,6 +124,15 @@ func Test_Accounts(t *testing.T) {
|
|||||||
|
|
||||||
_, err = db.GetAccountByLocalpart(ctx, "unusename")
|
_, err = db.GetAccountByLocalpart(ctx, "unusename")
|
||||||
assert.Error(t, err, "expected an error for non existent localpart")
|
assert.Error(t, err, "expected an error for non existent localpart")
|
||||||
|
|
||||||
|
// create an empty localpart; this should never happen, but is required to test getting a numeric localpart
|
||||||
|
// if there's already a user without a localpart in the database
|
||||||
|
_, err = db.CreateAccount(ctx, "", "", "", api.AccountTypeUser)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
// test getting a numeric localpart, with an existing user without a localpart
|
||||||
|
_, err = db.CreateAccount(ctx, "", "", "", api.AccountTypeGuest)
|
||||||
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user