validate ref strings when resolving ref specs

This commit is contained in:
Andy Arthur
2020-09-14 15:23:02 -07:00
parent 7b852f47e6
commit 5a01be5164
2 changed files with 14 additions and 4 deletions

View File

@@ -412,7 +412,7 @@ SQL
[ $output -eq $CORRECT_DIFF ]
}
@test "diff with branch@commit spec does not panic" {
@test "diff with invalid ref does not panic" {
dolt add .
dolt commit -m table
dolt checkout -b test-branch
@@ -420,7 +420,13 @@ SQL
dolt add test
dolt commit -m "added row"
FIRST_COMMIT=`dolt log | grep commit | cut -d " " -f 2 | tail -1`
dolt diff $FIRST_COMMIT test-branch
skip "The below panics."
dolt diff master@$FIRST_COMMIT test-branch
run dolt diff $FIRST_COMMIT test-branch
[ $status -eq 0 ]
[[ ! $output =~ "panic" ]]
run dolt diff master@$FIRST_COMMIT test-branch
[ $status -eq 1 ]
[[ ! $output =~ "panic" ]]
run dolt diff ref.with.period test-branch
[ $status -eq 1 ]
[[ ! $output =~ "panic" ]]
}

View File

@@ -187,6 +187,10 @@ func (ddb *DoltDB) WriteEmptyRepoWithCommitTime(ctx context.Context, name, email
}
func getCommitStForRefStr(ctx context.Context, db datas.Database, ref string) (types.Struct, error) {
if !datas.DatasetFullRe.MatchString(ref) {
return types.EmptyStruct(db.Format()), fmt.Errorf("invalid ref format: %s", ref)
}
ds, err := db.GetDataset(ctx, ref)
if err != nil {