fix: replace empty name result in panic

This commit is contained in:
li-jin-gou 2022-02-03 22:48:36 +08:00
parent f19b84d104
commit e31a21bfc0
2 changed files with 19 additions and 1 deletions

View File

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

View File

@ -197,3 +197,14 @@ func TestFormatNameWithStringLongerThan64Characters(t *testing.T) {
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)
}
}