fix: replace empty table name result in panic (#5048)

* fix: replace empty name result in panic

* fix: replace empty table name result in panic
This commit is contained in:
li-jin-gou 2022-02-08 17:06:10 +08:00 committed by GitHub
parent 416c4d0653
commit d22215129e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -120,7 +120,13 @@ func (ns NamingStrategy) toDBName(name string) string {
} }
if ns.NameReplacer != nil { if ns.NameReplacer != nil {
name = ns.NameReplacer.Replace(name) tmpName := ns.NameReplacer.Replace(name)
if tmpName == "" {
return name
}
name = tmpName
} }
if ns.NoLowerCase { if ns.NoLowerCase {

View File

@ -197,3 +197,14 @@ func TestFormatNameWithStringLongerThan64Characters(t *testing.T) {
t.Errorf("invalid formatted name generated, got %v", formattedName) t.Errorf("invalid formatted name generated, got %v", formattedName)
} }
} }
func TestReplaceEmptyTableName(t *testing.T) {
ns := NamingStrategy{
SingularTable: true,
NameReplacer: strings.NewReplacer("Model", ""),
}
tableName := ns.TableName("Model")
if tableName != "Model" {
t.Errorf("invalid table name generated, got %v", tableName)
}
}