Merge topic 'json-bom'

afa4e5f749 cmJSONState: Move BOM handling to shared helper
18a335e062 cmPListParser: Hand JSONState a seekable stream

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12466
This commit is contained in:
Brad King
2026-09-04 09:42:40 -04:00
committed by Kitware Robot
4 changed files with 17 additions and 5 deletions
+3 -2
View File
@@ -26,8 +26,6 @@ cmJSONState::cmJSONState(std::string jsonFile, Json::Value* root,
this->AddError(cmStrCat("File not found: ", this->Filename));
return;
}
// If there's a BOM, toss it.
cmsys::FStream::ReadBOM(fin);
this->ReadJSONStream(fin, root, strictMode);
}
@@ -127,6 +125,9 @@ void cmJSONState::pop_stack()
void cmJSONState::ReadJSONStream(std::istream& jsonIStream, Json::Value* root,
StrictMode strictMode)
{
// If there's a BOM, toss it.
cmsys::FStream::ReadBOM(jsonIStream);
// Save the entire document.
std::streampos inBegin = jsonIStream.tellg();
this->doc = std::string(std::istreambuf_iterator<char>(jsonIStream),
+12 -3
View File
@@ -2,6 +2,9 @@
file LICENSE.rst or https://cmake.org/licensing for details. */
#include "cmPlistParser.h"
#include <iterator>
#include <sstream>
#include <string>
#include <vector>
#include <cm3p/json/value.h>
@@ -25,10 +28,16 @@ cm::optional<Json::Value> cmParsePlist(std::string const& filename)
return cm::nullopt;
}
Json::Value value;
// Buffer plutil's output into a seekable stream. cmJSONState must be able
// peek at a leading BOM, which the process pipe behind cmUVIStream can't
// handle.
cmUVIStream outputStream(chain.OutputStream());
cmJSONState parseState(outputStream, &value,
cmJSONState::StrictMode::Relaxed);
std::string output{ std::istreambuf_iterator<char>(outputStream),
std::istreambuf_iterator<char>() };
std::istringstream jsonStream(output);
Json::Value value;
cmJSONState parseState(jsonStream, &value, cmJSONState::StrictMode::Relaxed);
if (!parseState.errors.empty()) {
return cm::nullopt;
}
+1
View File
@@ -1 +1,2 @@
array.json -text -whitespace
bom.json -text -whitespace
+1
View File
@@ -0,0 +1 @@