Skip to content

Commit 847423f

Browse files
rouaultgithub-actions[bot]
authored andcommitted
JSON import: reduce number of significant decimal digits when parsing id.version field (fixes OSGeo#3863, reworks previous commit)
1 parent 19cda6a commit 847423f

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/iso19111/io.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5981,7 +5981,7 @@ IdentifierNNPtr JSONParser::buildId(const json &j, bool removeInverseOf) {
59815981
static_cast<int>(dblVersion) == dblVersion) {
59825982
version = internal::toString(static_cast<int>(dblVersion));
59835983
} else {
5984-
version = internal::toString(dblVersion);
5984+
version = internal::toString(dblVersion, /*precision=*/15);
59855985
}
59865986
} else {
59875987
throw ParsingException("Unexpected type for value of \"version\"");

src/iso19111/metadata.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,15 +1142,9 @@ void Identifier::_exportToJSON(JSONFormatter *formatter) const {
11421142
if (!l_version.empty()) {
11431143
writer->AddObjKey("version");
11441144
bool isDouble = false;
1145-
const double dblVersion = c_locale_stod(l_version, isDouble);
1145+
(void)c_locale_stod(l_version, isDouble);
11461146
if (isDouble) {
1147-
if (dblVersion >= std::numeric_limits<int>::min() &&
1148-
dblVersion <= std::numeric_limits<int>::max() &&
1149-
static_cast<int>(dblVersion) == dblVersion) {
1150-
writer->Add(static_cast<int>(dblVersion));
1151-
} else {
1152-
writer->Add(dblVersion, /*precision=*/15);
1153-
}
1147+
writer->AddUnquoted(l_version.c_str());
11541148
} else {
11551149
writer->Add(l_version);
11561150
}

src/proj_json_streaming_writer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ void CPLJSonStreamingWriter::Add(const char *pszStr) {
219219
Print(FormatString(pszStr));
220220
}
221221

222+
void CPLJSonStreamingWriter::AddUnquoted(const char *pszStr) {
223+
EmitCommaIfNeeded();
224+
Print(pszStr);
225+
}
226+
222227
void CPLJSonStreamingWriter::Add(GIntBig nVal) {
223228
EmitCommaIfNeeded();
224229
Print(CPLSPrintf(CPL_FRMT_GIB, nVal));

src/proj_json_streaming_writer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class CPL_DLL CPLJSonStreamingWriter {
8686

8787
void Add(const std::string &str);
8888
void Add(const char *pszStr);
89+
void AddUnquoted(const char *pszStr);
8990
void Add(bool bVal);
9091
void Add(int nVal) { Add(static_cast<GIntBig>(nVal)); }
9192
void Add(unsigned int nVal) { Add(static_cast<GIntBig>(nVal)); }

0 commit comments

Comments
 (0)