base::JSONReader::ReadList requires options

This is being done by upstream to migrate the parser away from using
`JSON_PARSE_CHROMIUM_EXTENSIONS` as a default.

Chromium changes:
https://chromium.googlesource.com/chromium/src/+/606a5254fc9193a310de36fd750861eacce1d612

commit 606a5254fc9193a310de36fd750861eacce1d612
Author: Daniel Cheng <dcheng@chromium.org>
Date:   Mon Sep 22 21:42:27 2025 -0700

    Remove base::JSONReader::ReadList's default argument for parsing options

    Callers should be explicit if they need to opt into non-compliant JSON
    parsing that allows Chromium-specific extensions, e.g. comments.

    Bug: 446188265
    Change-Id: Icec12f00b124837e6820216cd87c9d52af47f4e5
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6975033
    Reviewed-by: Lei Zhang <thestig@chromium.org>
    Commit-Queue: Daniel Cheng <dcheng@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1519103}
This commit is contained in:
Claudio DeSouza
2025-10-15 20:31:10 -04:00
committed by Emerick Rogul
parent 1063709ad6
commit cc79061ccb
14 changed files with 36 additions and 26 deletions
@@ -37,8 +37,8 @@ ParseMappings(std::string_view entities, bool discard_irrelevant) {
auto& [entity_by_domain, entity_by_root_domain] = result;
// Parse the JSON
std::optional<base::Value::List> document =
base::JSONReader::ReadList(entities);
std::optional<base::Value::List> document = base::JSONReader::ReadList(
entities, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (!document) {
LOG(ERROR) << "Cannot parse the third-party entities list";
return {};
@@ -86,7 +86,8 @@ base::expected<std::vector<std::string>, std::string> UnBlindCreds(
return base::unexpected(std::move(batch_proof).error());
}
auto creds_base64 = base::JSONReader::ReadList(creds_batch.creds);
auto creds_base64 = base::JSONReader::ReadList(
creds_batch.creds, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
DCHECK(creds_base64.has_value());
std::vector<Token> creds;
for (auto& item : creds_base64.value()) {
@@ -97,8 +98,8 @@ base::expected<std::vector<std::string>, std::string> UnBlindCreds(
}
}
auto blinded_creds_base64 =
base::JSONReader::ReadList(creds_batch.blinded_creds);
auto blinded_creds_base64 = base::JSONReader::ReadList(
creds_batch.blinded_creds, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
DCHECK(blinded_creds_base64.has_value());
std::vector<BlindedToken> blinded_creds;
for (auto& item : blinded_creds_base64.value()) {
@@ -110,8 +111,8 @@ base::expected<std::vector<std::string>, std::string> UnBlindCreds(
}
}
auto signed_creds_base64 =
base::JSONReader::ReadList(creds_batch.signed_creds);
auto signed_creds_base64 = base::JSONReader::ReadList(
creds_batch.signed_creds, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
DCHECK(signed_creds_base64.has_value());
std::vector<SignedToken> signed_creds;
for (auto& item : signed_creds_base64.value()) {
@@ -150,7 +151,8 @@ base::expected<std::vector<std::string>, std::string> UnBlindCreds(
std::vector<std::string> UnBlindCredsMock(const mojom::CredsBatch& creds) {
std::vector<std::string> unblinded_encoded_creds;
auto signed_creds_base64 = base::JSONReader::ReadList(creds.signed_creds);
auto signed_creds_base64 = base::JSONReader::ReadList(
creds.signed_creds, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
DCHECK(signed_creds_base64.has_value());
for (auto& item : signed_creds_base64.value()) {
@@ -34,7 +34,8 @@ mojom::Result PostBalance::ParseBody(const std::string& body,
double* available) {
DCHECK(available);
std::optional<base::Value::List> value = base::JSONReader::ReadList(body);
std::optional<base::Value::List> value =
base::JSONReader::ReadList(body, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (!value) {
engine_->LogError(FROM_HERE) << "Invalid JSON";
return mojom::Result::FAILED;
@@ -81,7 +81,8 @@ GetCapabilities::ProcessResponse(const mojom::UrlResponse& response) const {
GetCapabilities::CapabilityMap GetCapabilities::ParseBody(
const std::string& body) const {
const auto value = base::JSONReader::ReadList(body);
const auto value =
base::JSONReader::ReadList(body, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (!value) {
engine_->LogError(FROM_HERE) << "Invalid body format";
return {};
@@ -47,7 +47,8 @@ mojom::Result GetCards::ParseBody(const std::string& body,
std::string* id) const {
DCHECK(id);
std::optional<base::Value::List> value = base::JSONReader::ReadList(body);
std::optional<base::Value::List> value =
base::JSONReader::ReadList(body, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (!value) {
engine_->LogError(FROM_HERE) << "Invalid JSON";
return mojom::Result::FAILED;
@@ -21,7 +21,8 @@ using Result = GetRecipientIDGemini::Result;
namespace {
Result ParseBody(RewardsEngine& engine, const std::string& body) {
auto value = base::JSONReader::ReadList(body);
auto value =
base::JSONReader::ReadList(body, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (!value) {
engine.LogError(FROM_HERE) << "Failed to parse body";
return base::unexpected(Error::kFailedToParseBody);
@@ -205,8 +205,8 @@ std::vector<FilterListCatalogEntry> FilterListCatalogFromJSON(
std::vector<FilterListCatalogEntry> catalog =
std::vector<FilterListCatalogEntry>();
std::optional<base::Value::List> parsed_json =
base::JSONReader::ReadList(catalog_json);
std::optional<base::Value::List> parsed_json = base::JSONReader::ReadList(
catalog_json, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (!parsed_json) {
LOG(ERROR) << "Could not load regional adblock catalog";
return catalog;
@@ -493,8 +493,8 @@ void BraveVpnService::GetAllRegions(GetAllRegionsCallback callback) {
void BraveVpnService::OnFetchRegionList(GetAllRegionsCallback callback,
const std::string& region_list,
bool success) {
std::optional<base::Value::List> value =
base::JSONReader::ReadList(region_list);
std::optional<base::Value::List> value = base::JSONReader::ReadList(
region_list, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (value) {
auto new_regions = ParseRegionList(*value);
std::vector<mojom::RegionPtr> regions;
@@ -239,8 +239,8 @@ void BraveVPNRegionDataManager::OnFetchRegionList(
CHECK_IS_TEST();
}
api_request_.reset();
std::optional<base::Value::List> value =
base::JSONReader::ReadList(region_list);
std::optional<base::Value::List> value = base::JSONReader::ReadList(
region_list, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (value && ParseAndCacheRegionList(*value, true)) {
VLOG(2) << "Got valid region list";
// Set default device region and it'll be updated when received valid
@@ -283,8 +283,8 @@ void BraveVPNRegionDataManager::OnFetchTimezones(
api_request_.reset();
if (success) {
std::optional<base::Value::List> value =
base::JSONReader::ReadList(timezones_list);
std::optional<base::Value::List> value = base::JSONReader::ReadList(
timezones_list, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
success = value.has_value();
if (success) {
SetDeviceRegionWithTimezone(*value);
@@ -122,8 +122,8 @@ void ConnectionAPIImpl::OnFetchHostnames(const std::string& region,
ResetAPIRequestInstance();
std::optional<base::Value::List> value =
base::JSONReader::ReadList(hostnames);
std::optional<base::Value::List> value = base::JSONReader::ReadList(
hostnames, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (value) {
ParseAndCacheHostnames(region, *value);
return;
@@ -45,7 +45,8 @@ base::Value::List LoadNavigationChain(const network::ResourceRequest& request) {
if (!de_amp_header) {
return base::Value::List().Append(base::Value(request.url.spec()));
}
auto value = base::JSONReader::ReadList(*de_amp_header);
auto value = base::JSONReader::ReadList(*de_amp_header,
base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (!value) {
return base::Value::List().Append(base::Value(request.url.spec()));
}
@@ -184,7 +184,8 @@ DebounceRule::ParseRules(std::string_view contents) {
if (contents.empty()) {
return base::unexpected("Could not obtain debounce configuration");
}
std::optional<base::Value::List> root = base::JSONReader::ReadList(contents);
std::optional<base::Value::List> root = base::JSONReader::ReadList(
contents, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (!root) {
return base::unexpected("Failed to parse debounce configuration");
}
+2 -1
View File
@@ -89,7 +89,8 @@ std::optional<std::vector<PsstRule>> PsstRule::ParseRules(
if (contents.empty()) {
return std::nullopt;
}
std::optional<base::Value::List> root = base::JSONReader::ReadList(contents);
std::optional<base::Value::List> root = base::JSONReader::ReadList(
contents, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (!root) {
VLOG(1) << "PsstRule::ParseRules: invalid JSON";
return std::nullopt;
@@ -91,7 +91,8 @@ RequestOTRRule::ParseRules(const std::string& contents) {
if (contents.empty()) {
return base::unexpected("Could not obtain request_otr configuration");
}
std::optional<base::Value::List> root = base::JSONReader::ReadList(contents);
std::optional<base::Value::List> root = base::JSONReader::ReadList(
contents, base::JSON_PARSE_CHROMIUM_EXTENSIONS);
if (!root) {
return base::unexpected("Failed to parse request_otr configuration");
}