Skip to content

Commit

Permalink
JSON export: avoid non-significant decimal digits in version field (f…
Browse files Browse the repository at this point in the history
…ixes #3863)
  • Loading branch information
rouault authored and github-actions[bot] committed Aug 28, 2023
1 parent 4f0376b commit 19cda6a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/iso19111/metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,10 +1088,11 @@ void Identifier::_exportToWKT(WKTFormatter *formatter) const {
formatter->addQuotedString(l_code);
}
if (!l_version.empty()) {
try {
(void)c_locale_stod(l_version);
bool isDouble = false;
(void)c_locale_stod(l_version, isDouble);
if (isDouble) {
formatter->add(l_version);
} catch (const std::exception &) {
} else {
formatter->addQuotedString(l_version);
}
}
Expand Down Expand Up @@ -1140,16 +1141,17 @@ void Identifier::_exportToJSON(JSONFormatter *formatter) const {

if (!l_version.empty()) {
writer->AddObjKey("version");
try {
const double dblVersion = c_locale_stod(l_version);
bool isDouble = false;
const double dblVersion = c_locale_stod(l_version, isDouble);
if (isDouble) {
if (dblVersion >= std::numeric_limits<int>::min() &&
dblVersion <= std::numeric_limits<int>::max() &&
static_cast<int>(dblVersion) == dblVersion) {
writer->Add(static_cast<int>(dblVersion));
} else {
writer->Add(dblVersion);
writer->Add(dblVersion, /*precision=*/15);
}
} catch (const std::exception &) {
} else {
writer->Add(l_version);
}
}
Expand Down

0 comments on commit 19cda6a

Please sign in to comment.