Skip to content

Commit e537449

Browse files
committed
fix(xlings): build the install_packages args with the JSON library
`[xlings] deps` is manifest input and the arguments were assembled by formatting the strings into a JSON literal, so a dependency name containing a quote or a backslash would emit malformed JSON. The failure would then surface as an xlings parse error naming neither the manifest nor the key that caused it. nlohmann::json is already imported in this translation unit (mcpp.libs.json), so this is `args["targets"] = declaredDeps; args["yes"] = true; args.dump()` and the escaping stops being something a reader has to verify by eye. No behaviour change for well-formed names, which is every name in practice -- this is about the failure mode of the one that is not.
1 parent 5d32ba8 commit e537449

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/build/prepare.cppm

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,16 +3080,20 @@ prepare_build(bool print_fingerprint,
30803080
// without pinning it. install_packages resolves the version
30813081
// itself and reports an ambiguous name with its candidates,
30823082
// which is the error the author can act on.
3083-
std::string targets;
3084-
for (auto const& d : declaredDeps) {
3085-
if (!targets.empty()) targets += ',';
3086-
targets += std::format("\"{}\"", d);
3087-
}
3083+
// Built with the JSON library rather than by formatting
3084+
// the strings in. `deps` is manifest input, so a name
3085+
// containing a quote or a backslash would otherwise emit
3086+
// malformed JSON and the failure would surface as an
3087+
// unrelated xlings parse error naming neither the manifest
3088+
// nor the key.
3089+
nlohmann::json args;
3090+
args["targets"] = declaredDeps;
3091+
args["yes"] = true;
3092+
30883093
mcpp::fetcher::InstallProgressHandler progress;
30893094
auto r = mcpp::xlings::call(
30903095
mcpp::config::make_xlings_env(**cfg2), "install_packages",
3091-
std::format(R"({{"targets":[{}],"yes":true}})", targets),
3092-
&progress);
3096+
args.dump(), &progress);
30933097
if (!r) {
30943098
// Shaped like the toolchain failure: say what failed and
30953099
// hand back a command the user can run themselves. An

0 commit comments

Comments
 (0)