Skip to content

Commit

Permalink
Merge pull request OSGeo#10807 from rouault/gml_lvbag_force_opening
Browse files Browse the repository at this point in the history
GML and LVBAG: honour IsSingleAllowedDriver()
  • Loading branch information
rouault authored Sep 16, 2024
2 parents 5b9e9e7 + 4216271 commit ca5b639
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
15 changes: 15 additions & 0 deletions autotest/ogr/ogr_gml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 11 additions & 0 deletions autotest/ogr/ogr_lvbag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions ogr/ogrsf_frmts/gml/ogrgmldriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(poOpenInfo->pabyHeader));
}
Expand Down
7 changes: 5 additions & 2 deletions ogr/ogrsf_frmts/lvbag/ogrlvbagdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(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") !=
Expand Down

0 comments on commit ca5b639

Please sign in to comment.