From a763a24e13a35fc2f1def08d93a60eebcf0ba290 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 15 Sep 2024 22:57:33 +0200 Subject: [PATCH] GML: honour IsSingleAllowedDriver() --- autotest/ogr/ogr_gml.py | 15 +++++++++++++++ ogr/ogrsf_frmts/gml/ogrgmldriver.cpp | 3 +++ 2 files changed, 18 insertions(+) diff --git a/autotest/ogr/ogr_gml.py b/autotest/ogr/ogr_gml.py index d4624b100a7b..ed21fe892650 100755 --- a/autotest/ogr/ogr_gml.py +++ b/autotest/ogr/ogr_gml.py @@ -4626,3 +4626,18 @@ def test_ogr_gml_get_layers_by_name_from_imported_schema_more_tests(tmp_path): assert isinstance( dat_erst, list ), f"Expected 'dat_erst' to be of type 'list', but got {type(dat_erst)}" + + +############################################################################### +# Test force opening a GML file + + +def test_ogr_gml_force_opening(tmp_vsimem): + + filename = str(tmp_vsimem / "test.gml") + gdal.FileFromMemBuffer(filename, open("data/nas/empty_nas.xml", "rb").read()) + + # Would be opened by NAS driver if not forced + with gdal.config_option("NAS_GFS_TEMPLATE", ""): + ds = gdal.OpenEx(filename, allowed_drivers=["GML"]) + assert ds.GetDriver().GetDescription() == "GML" diff --git a/ogr/ogrsf_frmts/gml/ogrgmldriver.cpp b/ogr/ogrsf_frmts/gml/ogrgmldriver.cpp index 9f633360c769..c180c298388b 100644 --- a/ogr/ogrsf_frmts/gml/ogrgmldriver.cpp +++ b/ogr/ogrsf_frmts/gml/ogrgmldriver.cpp @@ -75,6 +75,9 @@ static int OGRGMLDriverIdentify(GDALOpenInfo *poOpenInfo) if (!poOpenInfo->TryToIngest(4096)) return FALSE; + if (poOpenInfo->IsSingleAllowedDriver("GML")) + return TRUE; + return OGRGMLDataSource::CheckHeader( reinterpret_cast(poOpenInfo->pabyHeader)); }