Skip to content

Commit 9da8ae5

Browse files
authored
Merge pull request OSGeo#3841 from snowman2/guess
BUG: Handle prefix whitespace when guessing WKT dialiect
2 parents fde3d58 + d2794d7 commit 9da8ae5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/iso19111/io.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8015,7 +8015,12 @@ WKTParser::attachDatabaseContext(const DatabaseContextPtr &dbContext) {
80158015
/** \brief Guess the "dialect" of the WKT string.
80168016
*/
80178017
WKTParser::WKTGuessedDialect
8018-
WKTParser::guessDialect(const std::string &wkt) noexcept {
8018+
WKTParser::guessDialect(const std::string &inputWkt) noexcept {
8019+
std::string wkt = inputWkt;
8020+
std::size_t idxFirstCharNotSpace = wkt.find_first_not_of(" \t\r\n");
8021+
if (idxFirstCharNotSpace > 0 && idxFirstCharNotSpace != std::string::npos) {
8022+
wkt = wkt.substr(idxFirstCharNotSpace);
8023+
}
80198024
if (ci_starts_with(wkt, WKTConstants::VERTCS)) {
80208025
return WKTGuessedDialect::WKT1_ESRI;
80218026
}

test/unit/test_c_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2227,7 +2227,7 @@ TEST_F(CApi, proj_context_guess_wkt_dialect) {
22272227

22282228
EXPECT_EQ(proj_context_guess_wkt_dialect(
22292229
nullptr,
2230-
"GEOGCRS[\"WGS 84\",\n"
2230+
" \n\t\rGEOGCRS[\"WGS 84\",\n"
22312231
" DATUM[\"World Geodetic System 1984\",\n"
22322232
" ELLIPSOID[\"WGS 84\",6378137,298.257223563]],\n"
22332233
" CS[ellipsoidal,2],\n"

0 commit comments

Comments
 (0)