string(JSON): Include invalid JSON in parse error

This commit is contained in:
Martin Duffy
2025-07-11 11:16:39 -04:00
parent 5d3497ac10
commit 35f002e293
6 changed files with 53 additions and 19 deletions

View File

@@ -1059,7 +1059,8 @@ Json::Value ReadJson(std::string const& jsonstr)
std::string error;
if (!jsonReader->parse(jsonstr.data(), jsonstr.data() + jsonstr.size(),
&json, &error)) {
throw json_error(cmStrCat("failed parsing json string: "_s, error));
throw json_error(
cmStrCat("failed parsing json string:\n"_s, jsonstr, '\n', error));
}
return json;
}

View File

@@ -53,24 +53,26 @@ foreach(i RANGE ${length})
endforeach()
has_key_index(staticSystemInformation "${contents}" ${hasStaticInfo})
has_key_index(OSName "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(OSPlatform "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(OSRelease "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(OSVersion "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(familyId "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(hostname "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(is64Bits "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(modelId "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(numberOfLogicalCPU "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(numberOfPhysicalCPU "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(processorAPICID "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(processorCacheSize "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(processorClockFrequency "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(processorName "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(totalPhysicalMemory "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(totalVirtualMemory "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(vendorID "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(vendorString "${staticSystemInformation}" ${hasStaticInfo})
if (NOT hasStaticInfo STREQUAL UNEXPECTED)
has_key_index(OSName "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(OSPlatform "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(OSRelease "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(OSVersion "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(familyId "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(hostname "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(is64Bits "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(modelId "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(numberOfLogicalCPU "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(numberOfPhysicalCPU "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(processorAPICID "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(processorCacheSize "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(processorClockFrequency "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(processorName "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(totalPhysicalMemory "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(totalVirtualMemory "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(vendorID "${staticSystemInformation}" ${hasStaticInfo})
has_key_index(vendorString "${staticSystemInformation}" ${hasStaticInfo})
endif()
get_filename_component(dataDir ${index} DIRECTORY)
get_filename_component(v1 ${dataDir} DIRECTORY)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,26 @@
CMake Error at JSONBadJson.cmake:1 \(string\):
string sub-command JSON failed parsing json string:
invalid
\* Line 1, Column 1
Syntax error: value, object or array expected.
.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
CMake Error at JSONBadJson.cmake:2 \(string\):
string sub-command JSON failed parsing json string:
value
\* Line 1, Column 1
Syntax error: value, object or array expected.
.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)

View File

@@ -0,0 +1,3 @@
string(JSON badInput SET invalid key \"value\")
string(JSON badValue SET {} key value)
string(JSON good SET {} key \"value\")

View File

@@ -6,6 +6,7 @@ run_cmake(JSONNoJson)
run_cmake(JSONWrongMode)
run_cmake(JSONOneArg)
run_cmake(JSONNoArgs)
run_cmake(JSONBadJson)
run_cmake(Append)
run_cmake(AppendNoArgs)