diff --git a/go/libraries/doltcore/dbfactory/dirtodbname.go b/go/libraries/doltcore/dbfactory/dirtodbname.go index dc0d486fb2..e79480b9f1 100644 --- a/go/libraries/doltcore/dbfactory/dirtodbname.go +++ b/go/libraries/doltcore/dbfactory/dirtodbname.go @@ -25,11 +25,14 @@ import ( // DirToDBName takes the physical directory name, |dirName|, and replaces any unsupported characters to create a // valid logical database name. For example, spaces are replaced with underscores. func DirToDBName(dirName string) string { - // this environment variable is used whether to replace hyphens in the database name with underscores. - var translateHyphensToUnderscores = os.Getenv(dconfig.EnvDbNameReplaceHyphens) != "" + // this environment variable is used whether to replace hyphen and space characters in the database name with underscores. + if os.Getenv(dconfig.EnvDbNameReplace) == "" { + return dirName + } + dbName := strings.TrimSpace(dirName) dbName = strings.Map(func(r rune) rune { - if unicode.IsSpace(r) || (translateHyphensToUnderscores && r == '-') { + if unicode.IsSpace(r) || r == '-' { return '_' } return r diff --git a/go/libraries/doltcore/dconfig/envvars.go b/go/libraries/doltcore/dconfig/envvars.go index 630ff5a206..1e6bb440b4 100755 --- a/go/libraries/doltcore/dconfig/envvars.go +++ b/go/libraries/doltcore/dconfig/envvars.go @@ -42,5 +42,5 @@ const ( EnvDoltAssistAgree = "DOLT_ASSIST_AGREE" EnvDoltAuthorDate = "DOLT_AUTHOR_DATE" EnvDoltCommitterDate = "DOLT_COMMITTER_DATE" - EnvDbNameReplaceHyphens = "DOLT_DBNAME_REPLACE_HYPHENS" + EnvDbNameReplace = "DOLT_DBNAME_REPLACE" ) diff --git a/go/libraries/doltcore/env/multi_repo_env_test.go b/go/libraries/doltcore/env/multi_repo_env_test.go index b8bfadd1a0..49339c6129 100644 --- a/go/libraries/doltcore/env/multi_repo_env_test.go +++ b/go/libraries/doltcore/env/multi_repo_env_test.go @@ -38,7 +38,7 @@ func TestDirToDBName(t *testing.T) { " real - name ": "real_name", } - err := os.Setenv(dconfig.EnvDbNameReplaceHyphens, "true") + err := os.Setenv(dconfig.EnvDbNameReplace, "true") require.NoError(t, err) for dirName, expected := range replaceHyphenTests { @@ -49,10 +49,10 @@ func TestDirToDBName(t *testing.T) { allowHyphenTests := map[string]string{ "irs": "irs", "corona-virus": "corona-virus", - " fake - name ": "fake_-_name", + " fake - name ": " fake - name ", } - err = os.Setenv(dconfig.EnvDbNameReplaceHyphens, "") + err = os.Setenv(dconfig.EnvDbNameReplace, "") require.NoError(t, err) for dirName, expected := range allowHyphenTests { @@ -133,7 +133,7 @@ func TestMultiEnvForDirectory(t *testing.T) { expected := []envCmp{ { - name: "test---name_123", + name: " test---name _ 123", doltDir: dEnv.GetDoltDir(), }, } @@ -164,7 +164,7 @@ func TestMultiEnvForDirectoryWithMultipleRepos(t *testing.T) { assert.Len(t, mrEnv.envs, 3) expected := make(map[string]string) - expected["test---name_123"] = dEnv.GetDoltDir() + expected[" test---name _ 123"] = dEnv.GetDoltDir() expected["abc"] = subEnv1.GetDoltDir() expected["def"] = subEnv2.GetDoltDir() diff --git a/integration-tests/bats/db-revision-specifiers.bats b/integration-tests/bats/db-revision-specifiers.bats index 154c1591fa..b31f8e8386 100644 --- a/integration-tests/bats/db-revision-specifiers.bats +++ b/integration-tests/bats/db-revision-specifiers.bats @@ -3,7 +3,7 @@ load $BATS_TEST_DIRNAME/helper/common.bash setup() { setup_common - export DOLT_DBNAME_REPLACE_HYPHENS="true" + export DOLT_DBNAME_REPLACE="true" database_name=dolt_repo_$$ dolt sql -q "CREATE TABLE test(pk int PRIMARY KEY, color varchar(200))" diff --git a/integration-tests/bats/deleted-branches.bats b/integration-tests/bats/deleted-branches.bats index 036e59ffc6..adadc2d05d 100644 --- a/integration-tests/bats/deleted-branches.bats +++ b/integration-tests/bats/deleted-branches.bats @@ -6,7 +6,7 @@ setup() { skiponwindows "Missing dependencies" setup_common - export DOLT_DBNAME_REPLACE_HYPHENS="true" + export DOLT_DBNAME_REPLACE="true" } teardown() { diff --git a/integration-tests/bats/dump.bats b/integration-tests/bats/dump.bats index 3954f4e9ac..622c3b7296 100644 --- a/integration-tests/bats/dump.bats +++ b/integration-tests/bats/dump.bats @@ -16,6 +16,28 @@ teardown() { [[ "$output" =~ "No tables to export." ]] || false } +@test "dump: roundtrip on database with leading space character and hyphen" { + mkdir ' test-db' + cd ' test-db' + dolt init + create_tables + insert_data_into_tables + + run dolt dump + [ "$status" -eq 0 ] + [[ "$output" =~ "Successfully exported data." ]] || false + [ -f doltdump.sql ] + + mkdir roundtrip + cd roundtrip + dolt init + + dolt sql < ../doltdump.sql + run dolt sql -q "show databases" + [ $status -eq 0 ] + [[ $output =~ "| test-db" ]] || false +} + @test "dump: SQL type - with multiple tables" { dolt sql -q "CREATE TABLE new_table(pk int primary key);" dolt sql -q "INSERT INTO new_table VALUES (1);" diff --git a/integration-tests/bats/sql-checkout.bats b/integration-tests/bats/sql-checkout.bats index 21c0ca4d86..f1cad7c3a4 100644 --- a/integration-tests/bats/sql-checkout.bats +++ b/integration-tests/bats/sql-checkout.bats @@ -130,7 +130,7 @@ SQL } @test "sql-checkout: DOLT_CHECKOUT updates the head ref session var" { - export DOLT_DBNAME_REPLACE_HYPHENS="true" + export DOLT_DBNAME_REPLACE="true" run dolt sql <