Skip to content

Commit

Permalink
JSON import: reduce number of significant decimal digits when parsing…
Browse files Browse the repository at this point in the history
… id.version field (fixes #3863, reworks previous commit)
  • Loading branch information
rouault authored and github-actions[bot] committed Aug 28, 2023
1 parent 19cda6a commit 847423f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5981,7 +5981,7 @@ IdentifierNNPtr JSONParser::buildId(const json &j, bool removeInverseOf) {
static_cast<int>(dblVersion) == dblVersion) {
version = internal::toString(static_cast<int>(dblVersion));
} else {
version = internal::toString(dblVersion);
version = internal::toString(dblVersion, /*precision=*/15);
}
} else {
throw ParsingException("Unexpected type for value of \"version\"");
Expand Down
10 changes: 2 additions & 8 deletions src/iso19111/metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,15 +1142,9 @@ void Identifier::_exportToJSON(JSONFormatter *formatter) const {
if (!l_version.empty()) {
writer->AddObjKey("version");
bool isDouble = false;
const double dblVersion = c_locale_stod(l_version, isDouble);
(void)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, /*precision=*/15);
}
writer->AddUnquoted(l_version.c_str());
} else {
writer->Add(l_version);
}
Expand Down
5 changes: 5 additions & 0 deletions src/proj_json_streaming_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ void CPLJSonStreamingWriter::Add(const char *pszStr) {
Print(FormatString(pszStr));
}

void CPLJSonStreamingWriter::AddUnquoted(const char *pszStr) {
EmitCommaIfNeeded();
Print(pszStr);
}

void CPLJSonStreamingWriter::Add(GIntBig nVal) {
EmitCommaIfNeeded();
Print(CPLSPrintf(CPL_FRMT_GIB, nVal));
Expand Down
1 change: 1 addition & 0 deletions src/proj_json_streaming_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class CPL_DLL CPLJSonStreamingWriter {

void Add(const std::string &str);
void Add(const char *pszStr);
void AddUnquoted(const char *pszStr);
void Add(bool bVal);
void Add(int nVal) { Add(static_cast<GIntBig>(nVal)); }
void Add(unsigned int nVal) { Add(static_cast<GIntBig>(nVal)); }
Expand Down

0 comments on commit 847423f

Please sign in to comment.