From 421627106e9eb11f2cbeceadfc4b883840a384ec Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 15 Sep 2024 22:57:45 +0200 Subject: [PATCH] LVBAG: honour IsSingleAllowedDriver() --- autotest/ogr/ogr_lvbag.py | 11 +++++++++++ ogr/ogrsf_frmts/lvbag/ogrlvbagdriver.cpp | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/autotest/ogr/ogr_lvbag.py b/autotest/ogr/ogr_lvbag.py index 24154c580b6d..250aeeafffbb 100644 --- a/autotest/ogr/ogr_lvbag.py +++ b/autotest/ogr/ogr_lvbag.py @@ -603,3 +603,14 @@ def test_ogr_lvbag_test_ogrsf_num(): ) assert "INFO" in ret and "ERROR" not in ret + + +############################################################################### +# Test force opening + + +def test_ogr_lvbag_force_opening(): + + # Would be opened by GML driver if not forced + ds = gdal.OpenEx("data/gml/empty.gml", allowed_drivers=["LVBAG"]) + assert ds.GetDriver().GetDescription() == "LVBAG" diff --git a/ogr/ogrsf_frmts/lvbag/ogrlvbagdriver.cpp b/ogr/ogrsf_frmts/lvbag/ogrlvbagdriver.cpp index b6e3b5a094de..e86dface9039 100644 --- a/ogr/ogrsf_frmts/lvbag/ogrlvbagdriver.cpp +++ b/ogr/ogrsf_frmts/lvbag/ogrlvbagdriver.cpp @@ -39,13 +39,16 @@ static int OGRLVBAGDriverIdentify(GDALOpenInfo *poOpenInfo) return FALSE; if (poOpenInfo->bIsDirectory) return -1; // Check later - if (poOpenInfo->fpL == nullptr) + if (poOpenInfo->fpL == nullptr || poOpenInfo->nHeaderBytes == 0) return FALSE; auto pszPtr = reinterpret_cast(poOpenInfo->pabyHeader); - if (poOpenInfo->nHeaderBytes == 0 || pszPtr[0] != '<') + if (pszPtr[0] != '<') return FALSE; + if (poOpenInfo->IsSingleAllowedDriver("LVBAG")) + return TRUE; + // Can't handle mutations just yet if (strstr(pszPtr, "http://www.kadaster.nl/schemas/mutatielevering-generiek/1.0") !=