diff --git a/radiantcore/map/Map.cpp b/radiantcore/map/Map.cpp index 9b3e4aabde..07bf7f1a75 100644 --- a/radiantcore/map/Map.cpp +++ b/radiantcore/map/Map.cpp @@ -721,6 +721,12 @@ void Map::saveSelected(const std::string& filename, const MapFormatPtr& mapForma format = GlobalMapFormatManager().getMapFormatForFilename(filename); } + // Fall back to the format of the current map if the selection is empty (#5808) + if (!format) + { + format = getFormat(); + } + try { MapResource::saveFile( @@ -1154,7 +1160,7 @@ void Map::exportSelection(const cmd::ArgumentList& args) MapFileSelection fileInfo = MapFileManager::getMapFileSelection(false, _("Export selection"), filetype::TYPE_MAP); - if (!fileInfo.fullPath.empty()) + if (!fileInfo.fullPath.empty()) { GlobalMap().saveSelected(fileInfo.fullPath, fileInfo.mapFormat); } diff --git a/test/MapExport.cpp b/test/MapExport.cpp index 3bfcc85ab9..af1b3b2ac2 100644 --- a/test/MapExport.cpp +++ b/test/MapExport.cpp @@ -289,14 +289,17 @@ brushDef3 EXPECT_NE(brushTextIndex, std::string::npos) << "Could not locate the exported brush in the expected format"; } -TEST_F(MapExportTest, ExportSelectedWithEmptyFileExtension) +namespace +{ + +void runExportWithEmptyFileExtension(const std::string& temporaryDataPath,const std::string& command) { auto brush = algorithm::createCuboidBrush(GlobalMapModule().findOrInsertWorldspawn(), AABB(Vector3(0, 0, 0), Vector3(64, 128, 256)), "textures/darkmod/numbers/1"); Node_setSelected(brush, true); - fs::path tempPath = _context.getTemporaryDataPath(); + fs::path tempPath = temporaryDataPath; tempPath /= "export_empty_file_extension"; EXPECT_FALSE(fs::exists(tempPath)) << "File already exists"; @@ -313,7 +316,7 @@ TEST_F(MapExportTest, ExportSelectedWithEmptyFileExtension) "" // this can happen if e.g. the *.* filter is active }); })); - GlobalCommandSystem().executeCommand("SaveSelected"); + GlobalCommandSystem().executeCommand(command); EXPECT_TRUE(fs::exists(tempPath)) << "File still doesn't exist"; @@ -325,3 +328,15 @@ TEST_F(MapExportTest, ExportSelectedWithEmptyFileExtension) } } + +TEST_F(MapExportTest, ExportSelectedWithEmptyFileExtension) +{ + runExportWithEmptyFileExtension(_context.getTemporaryDataPath(), "SaveSelected"); +} + +TEST_F(MapExportTest, ExportPrefabWithEmptyFileExtension) +{ + runExportWithEmptyFileExtension(_context.getTemporaryDataPath(), "SaveSelectedAsPrefab"); +} + +}