fix: prevent a crash if there is a unique key constraint with a nil field. (#3770)

master
POABOB 12 months ago committed by GitHub
parent 22c98beb24
commit a1bbac3c6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -83,8 +83,9 @@ func Parse(filename, database string, strict bool) ([]*Table, error) {
primaryColumn string primaryColumn string
primaryColumnSet = collection.NewSet() primaryColumnSet = collection.NewSet()
uniqueKeyMap = make(map[string][]string) uniqueKeyMap = make(map[string][]string)
normalKeyMap = make(map[string][]string) // Unused local variable
columns = e.Columns // normalKeyMap = make(map[string][]string)
columns = e.Columns
) )
for _, column := range columns { for _, column := range columns {
@ -144,20 +145,26 @@ func Parse(filename, database string, strict bool) ([]*Table, error) {
var ( var (
uniqueIndex = make(map[string][]*Field) uniqueIndex = make(map[string][]*Field)
normalIndex = make(map[string][]*Field) // Unused local variable
// normalIndex = make(map[string][]*Field)
) )
for indexName, each := range uniqueKeyMap { for indexName, each := range uniqueKeyMap {
for _, columnName := range each { for _, columnName := range each {
// Prevent a crash if there is a unique key constraint with a nil field.
if fieldM[columnName] == nil {
return nil, fmt.Errorf("table %s: unique key with error column name[%s]", e.Name, columnName)
}
uniqueIndex[indexName] = append(uniqueIndex[indexName], fieldM[columnName]) uniqueIndex[indexName] = append(uniqueIndex[indexName], fieldM[columnName])
} }
} }
for indexName, each := range normalKeyMap { // Unused local variable
for _, columnName := range each { // for indexName, each := range normalKeyMap {
normalIndex[indexName] = append(normalIndex[indexName], fieldM[columnName]) // for _, columnName := range each {
} // normalIndex[indexName] = append(normalIndex[indexName], fieldM[columnName])
} // }
// }
checkDuplicateUniqueIndex(uniqueIndex, e.Name) checkDuplicateUniqueIndex(uniqueIndex, e.Name)

Loading…
Cancel
Save