From 5a01be5164914ce67da362953ef6849d290bc372 Mon Sep 17 00:00:00 2001 From: Andy Arthur Date: Mon, 14 Sep 2020 15:23:02 -0700 Subject: [PATCH] validate ref strings when resolving ref specs --- bats/diff.bats | 14 ++++++++++---- go/libraries/doltcore/doltdb/doltdb.go | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bats/diff.bats b/bats/diff.bats index 350a76045f..251f3bf10c 100644 --- a/bats/diff.bats +++ b/bats/diff.bats @@ -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" ]] } diff --git a/go/libraries/doltcore/doltdb/doltdb.go b/go/libraries/doltcore/doltdb/doltdb.go index 30af657c47..060c87a20b 100644 --- a/go/libraries/doltcore/doltdb/doltdb.go +++ b/go/libraries/doltcore/doltdb/doltdb.go @@ -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 {