From 0b5dc4fe06c03c0e1e965d70e5ba9b0de4cb7321 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 23 Oct 2026 16:13:28 -0300 Subject: [PATCH] Upgrade Sourcemeta dependencies Signed-off-by: Juan Cruz Viotti --- DEPENDENCIES | 4 +- vendor/blaze/DEPENDENCIES | 2 +- vendor/blaze/schemas/canonical-draft4.json | 193 ++++------ vendor/blaze/src/alterschema/alterschema.cc | 15 + .../alterschema/common/anyof_true_simplify.h | 3 +- .../common/double_negation_elimination.h | 3 + .../alterschema/common/draft_ref_siblings.h | 3 +- .../common/drop_allof_empty_schemas.h | 3 +- .../common/duplicate_allof_branches.h | 3 +- .../common/duplicate_anyof_branches.h | 3 +- .../common/duplicate_enum_values.h | 3 +- .../common/duplicate_required_values.h | 3 +- .../src/alterschema/common/enum_with_type.h | 3 +- .../common/equal_numeric_bounds_to_enum.h | 7 +- .../common/exclusive_bounds_false_drop.h | 3 +- .../alterschema/common/flatten_nested_allof.h | 3 +- .../alterschema/common/flatten_nested_anyof.h | 3 +- .../common/maximum_real_for_integer.h | 3 +- .../common/minimum_real_for_integer.h | 3 +- .../non_applicable_enum_validation_keywords.h | 3 +- .../non_applicable_type_specific_keywords.h | 6 +- .../common/oneof_to_anyof_disjoint_types.h | 11 +- .../required_properties_in_properties.h | 6 +- .../alterschema/common/unknown_local_ref.h | 3 +- .../unnecessary_allof_ref_wrapper_draft.h | 3 +- .../common/unsatisfiable_drop_validation.h | 16 +- .../unsatisfiable_in_place_applicator_type.h | 2 + .../linter/conflicting_readonly_writeonly.h | 3 +- .../linter/description_trailing_period.h | 3 +- .../src/alterschema/linter/description_trim.h | 3 +- .../alterschema/linter/forbid_empty_enum.h | 3 +- .../alterschema/linter/invalid_external_ref.h | 3 +- .../alterschema/linter/items_schema_default.h | 12 +- .../alterschema/linter/multiple_of_default.h | 3 +- .../linter/pattern_non_ecma_regex.h | 3 +- .../alterschema/linter/properties_default.h | 3 +- .../linter/simple_properties_identifiers.h | 3 +- .../linter/title_description_equal.h | 3 +- .../linter/title_trailing_period.h | 3 +- .../blaze/src/alterschema/linter/title_trim.h | 3 +- .../linter/top_level_description.h | 3 +- .../src/alterschema/linter/top_level_title.h | 3 +- .../linter/unknown_format_prefix.h | 10 + .../linter/unnecessary_allof_wrapper.h | 20 +- .../linter/unsatisfiable_min_properties.h | 3 +- .../src/alterschema/linter/valid_default.h | 5 +- .../blaze/src/canonicalizer/canonicalize.cc | 346 ++++++++++++------ .../src/codegen/codegen_default_compiler.h | 4 +- vendor/blaze/src/compiler/compile.cc | 23 +- .../src/compiler/default_compiler_draft3.h | 196 +++------- .../src/compiler/default_compiler_draft4.h | 33 +- .../core/src/core/crypto/crypto_hkdf_apple.cc | 4 + .../src/core/crypto/crypto_hkdf_openssl.cc | 4 + .../src/core/crypto/crypto_hkdf_windows.cc | 8 + .../src/core/crypto/crypto_rsa_oaep_apple.cc | 4 + .../core/crypto/crypto_rsa_oaep_openssl.cc | 4 + .../core/crypto/crypto_rsa_oaep_windows.cc | 4 + .../core/src/core/crypto/crypto_sign_apple.cc | 24 ++ .../src/core/crypto/crypto_sign_openssl.cc | 16 + .../src/core/crypto/crypto_sign_windows.cc | 24 ++ .../src/core/crypto/crypto_verify_apple.cc | 16 + .../src/core/crypto/crypto_verify_openssl.cc | 12 + .../src/core/crypto/crypto_verify_windows.cc | 16 + vendor/core/src/core/diff/diff.cc | 44 ++- vendor/core/src/core/diff/myers.h | 22 +- vendor/core/src/core/dns/idn_hostname.cc | 11 +- vendor/core/src/core/gzip/inflate.h | 17 +- vendor/core/src/core/http/from_date.cc | 2 +- .../core/http/include/sourcemeta/core/http.h | 2 +- .../include/sourcemeta/core/http_message.h | 34 +- vendor/core/src/core/idna/idna.cc | 21 +- vendor/core/src/core/jsonld/jsonld.cc | 11 +- .../core/src/core/jsonld/jsonld_compaction.cc | 37 +- .../core/jsonld/jsonld_context_processing.cc | 7 +- .../core/src/core/jsonld/jsonld_expansion.cc | 41 ++- .../src/core/jsonld/jsonld_iri_compaction.cc | 7 +- .../core/src/core/jsonld/jsonld_node_map.cc | 16 +- .../core/src/core/jsonld/jsonld_serialise.h | 2 +- vendor/core/src/core/jsonpath/jsonpath.cc | 71 ++-- vendor/core/src/core/jsonpath/parser.h | 3 + vendor/core/src/core/jsonpointer/position.cc | 63 ++-- .../src/core/jsonschema/known_resolver.cmake | 18 +- .../src/core/jsonschema/known_resolver.in.cc | 34 +- .../core/src/core/jsonschema/known_walker.cc | 2 +- .../include/sourcemeta/core/markdown.h | 20 +- vendor/core/src/core/markdown/markdown.cc | 13 +- vendor/core/src/core/mcp/headers.cc | 15 +- .../sourcemeta/core/mcp_capabilities.h | 24 +- .../mcp/include/sourcemeta/core/mcp_error.h | 56 ++- .../mcp/include/sourcemeta/core/mcp_headers.h | 34 +- .../mcp/include/sourcemeta/core/mcp_logging.h | 17 +- .../include/sourcemeta/core/mcp_protocol.h | 106 ++++-- .../mcp/include/sourcemeta/core/mcp_results.h | 262 +++++++------ vendor/core/src/core/mcp/notifications.cc | 14 +- vendor/core/src/core/mcp/parameter_headers.cc | 11 +- vendor/core/src/core/mcp/results.cc | 88 ++++- vendor/core/src/core/mcp/validation.h | 49 ++- .../core/src/core/oidc/oidc_authentication.cc | 9 +- vendor/core/src/core/oidc/oidc_id_token.cc | 9 +- .../include/sourcemeta/core/punycode.h | 54 ++- vendor/core/src/core/punycode/punycode.cc | 60 ++- vendor/core/src/core/regex/permissive.h | 37 +- vendor/core/src/core/regex/regex.cc | 54 +-- vendor/core/src/core/semver/semver.cc | 14 +- vendor/core/src/core/terminal/terminal.cc | 8 +- vendor/core/src/core/time/asctime.cc | 6 +- vendor/core/src/core/time/imf_fixdate.cc | 6 +- .../core/time/include/sourcemeta/core/time.h | 6 +- vendor/core/src/core/time/rfc850_date.cc | 6 +- vendor/core/src/core/uri/parse.cc | 94 ++--- vendor/core/src/core/uri/setters.cc | 41 +-- vendor/core/src/core/uritemplate/helpers.h | 16 +- .../core/uritemplate/uritemplate_router.cc | 13 +- .../uritemplate/uritemplate_router_view.cc | 10 +- vendor/core/src/lang/io/io.cc | 18 +- .../core/src/lang/numeric/big_coefficient.h | 19 +- .../sourcemeta/core/parallel_for_each.h | 23 +- 117 files changed, 1639 insertions(+), 1181 deletions(-) diff --git a/DEPENDENCIES b/DEPENDENCIES index 877bcbd7d..b092b3953 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -1,4 +1,4 @@ vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02 -core https://github.com/sourcemeta/core af2b932ef6284c880f47012749b78bb75526f7a4 -blaze https://github.com/sourcemeta/blaze a5a019aa49139e7cd21accd52ad2c65f66afff16 +core https://github.com/sourcemeta/core 3ce74df56f5f2a43555137ad0993d755096a54be +blaze https://github.com/sourcemeta/blaze 0e6f12f56dca8c909a5561ab6541cb41ec07b6be bootstrap https://github.com/twbs/bootstrap 1a6fdfae6be09b09eaced8f0e442ca6f7680a61e diff --git a/vendor/blaze/DEPENDENCIES b/vendor/blaze/DEPENDENCIES index aa4dbae86..cb5e4a31c 100644 --- a/vendor/blaze/DEPENDENCIES +++ b/vendor/blaze/DEPENDENCIES @@ -1,3 +1,3 @@ vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02 -core https://github.com/sourcemeta/core af2b932ef6284c880f47012749b78bb75526f7a4 +core https://github.com/sourcemeta/core 5181fd3a3ea5f08df23c833a0cf60b08cd7be00f jsonschema-test-suite https://github.com/json-schema-org/JSON-Schema-Test-Suite 6648e8194c69697b2e1a15fe76a06a480b183a51 diff --git a/vendor/blaze/schemas/canonical-draft4.json b/vendor/blaze/schemas/canonical-draft4.json index 7deb608b1..d397dbfc8 100644 --- a/vendor/blaze/schemas/canonical-draft4.json +++ b/vendor/blaze/schemas/canonical-draft4.json @@ -2,20 +2,24 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "tag:sourcemeta.com,2026:canonical:draft4", "title": "Canonical JSON Schema Draft 4", - "description": "Meta-schema that validates whether a given JSON Schema Draft 4 document is in canonical form", + "description": "Meta-schema that validates whether a given JSON Schema Draft 4 document is in canonical graph form", "examples": [ { - "$ref": "#/definitions/foo" - }, - { - "enum": [ 1, 2, 3 ] - }, - { - "type": "string", - "minLength": 0 + "$schema": "http://json-schema.org/draft-04/schema#", + "allOf": [ + { + "$ref": "#/definitions/0" + } + ], + "definitions": { + "0": { + "type": "string", + "minLength": 0 + } + } } ], - "$ref": "#/$defs/schema", + "$ref": "#/$defs/document", "$defs": { "metadata": { "properties": { @@ -31,25 +35,54 @@ "^x-": true } }, - "core": { + "document": { "x-lint-exclude": "simple_properties_identifiers", + "type": "object", + "required": [ "allOf", "definitions" ], "properties": { "$schema": { "type": "string" }, - "id": { - "type": "string" + "allOf": { + "type": "array", + "maxItems": 1, + "minItems": 1, + "items": { + "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/edge", + "properties": { + "$ref": { + "const": "#/definitions/0" + } + } + } }, "definitions": { "type": "object", "minProperties": 1, + "propertyNames": { + "pattern": "^(0|[1-9][0-9]*)$" + }, "additionalProperties": { - "$ref": "#/$defs/schema" + "$ref": "#/$defs/node" } } - } + }, + "unevaluatedProperties": false }, - "schema": { + "edge": { + "x-lint-exclude": "simple_properties_identifiers", + "type": "object", + "required": [ "$ref" ], + "properties": { + "$ref": { + "type": "string", + "pattern": "^#/definitions/(0|[1-9][0-9]*)$" + } + }, + "unevaluatedProperties": false + }, + "node": { "anyOf": [ { "const": {} @@ -58,6 +91,15 @@ "x-lint-exclude": "simple_properties_identifiers", "$ref": "#/$defs/metadata", "type": "object", + "not": { + "x-lint-exclude": "simple_properties_identifiers", + "maxProperties": 1, + "properties": { + "$ref": { + "pattern": "^#" + } + } + }, "required": [ "$ref" ], "properties": { "$ref": { @@ -68,15 +110,8 @@ }, { "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/metadata", "type": "object", - "allOf": [ - { - "$ref": "#/$defs/metadata" - }, - { - "$ref": "#/$defs/core" - } - ], "required": [ "enum" ], "properties": { "enum": { @@ -121,15 +156,8 @@ }, { "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/metadata", "type": "object", - "allOf": [ - { - "$ref": "#/$defs/metadata" - }, - { - "$ref": "#/$defs/core" - } - ], "required": [ "type", "minLength" ], "properties": { "type": { @@ -154,15 +182,8 @@ }, { "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/metadata", "type": "object", - "allOf": [ - { - "$ref": "#/$defs/metadata" - }, - { - "$ref": "#/$defs/core" - } - ], "required": [ "type", "multipleOf" ], "properties": { "type": { @@ -183,15 +204,8 @@ }, { "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/metadata", "type": "object", - "allOf": [ - { - "$ref": "#/$defs/metadata" - }, - { - "$ref": "#/$defs/core" - } - ], "required": [ "type" ], "properties": { "type": { @@ -218,15 +232,8 @@ }, { "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/metadata", "type": "object", - "allOf": [ - { - "$ref": "#/$defs/metadata" - }, - { - "$ref": "#/$defs/core" - } - ], "required": [ "type", "properties", @@ -241,19 +248,19 @@ "properties": { "type": "object", "additionalProperties": { - "$ref": "#/$defs/schema" + "$ref": "#/$defs/edge" } }, "patternProperties": { "type": "object", "additionalProperties": { - "$ref": "#/$defs/schema" + "$ref": "#/$defs/edge" } }, "additionalProperties": { "anyOf": [ { - "$ref": "#/$defs/schema" + "$ref": "#/$defs/edge" }, { "type": "boolean" @@ -281,22 +288,15 @@ }, { "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/metadata", "type": "object", - "allOf": [ - { - "$ref": "#/$defs/metadata" - }, - { - "$ref": "#/$defs/core" - } - ], "required": [ "type", "items", "minItems", "uniqueItems" ], "properties": { "type": { "const": "array" }, "items": { - "$ref": "#/$defs/schema" + "$ref": "#/$defs/edge" }, "minItems": { "type": "integer", @@ -314,15 +314,8 @@ }, { "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/metadata", "type": "object", - "allOf": [ - { - "$ref": "#/$defs/metadata" - }, - { - "$ref": "#/$defs/core" - } - ], "required": [ "type", "items", @@ -338,13 +331,13 @@ "type": "array", "minItems": 1, "items": { - "$ref": "#/$defs/schema" + "$ref": "#/$defs/edge" } }, "additionalItems": { "anyOf": [ { - "$ref": "#/$defs/schema" + "$ref": "#/$defs/edge" }, { "type": "boolean" @@ -367,15 +360,8 @@ }, { "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/metadata", "type": "object", - "allOf": [ - { - "$ref": "#/$defs/metadata" - }, - { - "$ref": "#/$defs/core" - } - ], "required": [ "anyOf" ], "properties": { "anyOf": { @@ -383,7 +369,7 @@ "minItems": 2, "uniqueItems": true, "items": { - "$ref": "#/$defs/schema" + "$ref": "#/$defs/edge" } } }, @@ -391,15 +377,8 @@ }, { "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/metadata", "type": "object", - "allOf": [ - { - "$ref": "#/$defs/metadata" - }, - { - "$ref": "#/$defs/core" - } - ], "required": [ "allOf" ], "properties": { "allOf": { @@ -407,7 +386,7 @@ "minItems": 2, "uniqueItems": true, "items": { - "$ref": "#/$defs/schema" + "$ref": "#/$defs/edge" } } }, @@ -415,22 +394,15 @@ }, { "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/metadata", "type": "object", - "allOf": [ - { - "$ref": "#/$defs/metadata" - }, - { - "$ref": "#/$defs/core" - } - ], "required": [ "oneOf" ], "properties": { "oneOf": { "type": "array", "minItems": 2, "items": { - "$ref": "#/$defs/schema" + "$ref": "#/$defs/edge" } } }, @@ -438,19 +410,12 @@ }, { "x-lint-exclude": "simple_properties_identifiers", + "$ref": "#/$defs/metadata", "type": "object", - "allOf": [ - { - "$ref": "#/$defs/metadata" - }, - { - "$ref": "#/$defs/core" - } - ], "required": [ "not" ], "properties": { "not": { - "$ref": "#/$defs/schema" + "$ref": "#/$defs/edge" } }, "unevaluatedProperties": false diff --git a/vendor/blaze/src/alterschema/alterschema.cc b/vendor/blaze/src/alterschema/alterschema.cc index e27e0eb61..f3739950d 100644 --- a/vendor/blaze/src/alterschema/alterschema.cc +++ b/vendor/blaze/src/alterschema/alterschema.cc @@ -84,6 +84,21 @@ inline auto is_known_type_form(const JSON &type, }); } +// OpenAPI 3.0 bans `type: "null"` and offers `nullable` in its place, which +// widens a sibling `type` and nothing else. It takes effect only where `type` +// is present, so on its own it constrains nothing +inline auto is_nullable(const JSON &schema, + const SchemaVocabularies &vocabularies) -> bool { + if (!vocabularies.contains(SchemaVocabularies::Known::OPENAPI_3_0_BASE) || + !schema.is_object()) { + return false; + } + + const auto *nullable{schema.try_at("nullable")}; + return nullable != nullptr && nullable->is_boolean() && + nullable->to_boolean(); +} + // Walk up from a schema location, continuing as long as the traversal // predicate returns true for each keyword type encountered. Returns a // reference to the pointer of the ancestor where the match callback returned diff --git a/vendor/blaze/src/alterschema/common/anyof_true_simplify.h b/vendor/blaze/src/alterschema/common/anyof_true_simplify.h index ddf027bda..c471c8322 100644 --- a/vendor/blaze/src/alterschema/common/anyof_true_simplify.h +++ b/vendor/blaze/src/alterschema/common/anyof_true_simplify.h @@ -23,7 +23,8 @@ class AnyOfTrueSimplify final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_APPLICATOR, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object() && schema.defines(KEYWORD) && schema.at(KEYWORD).is_array()); diff --git a/vendor/blaze/src/alterschema/common/double_negation_elimination.h b/vendor/blaze/src/alterschema/common/double_negation_elimination.h index 93d275221..41a9be1d1 100644 --- a/vendor/blaze/src/alterschema/common/double_negation_elimination.h +++ b/vendor/blaze/src/alterschema/common/double_negation_elimination.h @@ -18,6 +18,9 @@ class DoubleNegationElimination final : public SchemaTransformRule { const sourcemeta::core::SchemaResolver &) const -> SchemaTransformRule::Result override { static const JSON::String KEYWORD{"not"}; + // The OpenAPI 3.0 Schema Object is deliberately absent, as merging the + // inner schema can place a `nullable` beside a `type` it never sat next + // to, which widens what that type admits ONLY_CONTINUE_IF( vocabularies.contains_any( {SchemaVocabularies::Known::JSON_SCHEMA_2020_12_APPLICATOR, diff --git a/vendor/blaze/src/alterschema/common/draft_ref_siblings.h b/vendor/blaze/src/alterschema/common/draft_ref_siblings.h index 4fc78aba5..0c553cff4 100644 --- a/vendor/blaze/src/alterschema/common/draft_ref_siblings.h +++ b/vendor/blaze/src/alterschema/common/draft_ref_siblings.h @@ -24,7 +24,8 @@ class DraftRefSiblings final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_0})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_0, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object() && schema.defines("$ref")); std::vector locations; diff --git a/vendor/blaze/src/alterschema/common/drop_allof_empty_schemas.h b/vendor/blaze/src/alterschema/common/drop_allof_empty_schemas.h index e5ffcf341..a9b1a91e5 100644 --- a/vendor/blaze/src/alterschema/common/drop_allof_empty_schemas.h +++ b/vendor/blaze/src/alterschema/common/drop_allof_empty_schemas.h @@ -16,7 +16,8 @@ class DropAllOfEmptySchemas final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_APPLICATOR, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); const auto *all_of{schema.try_at("allOf")}; ONLY_CONTINUE_IF(all_of && all_of->is_array() && !all_of->empty()); diff --git a/vendor/blaze/src/alterschema/common/duplicate_allof_branches.h b/vendor/blaze/src/alterschema/common/duplicate_allof_branches.h index 7d4833495..ba05b500b 100644 --- a/vendor/blaze/src/alterschema/common/duplicate_allof_branches.h +++ b/vendor/blaze/src/alterschema/common/duplicate_allof_branches.h @@ -25,7 +25,8 @@ class DuplicateAllOfBranches final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_APPLICATOR, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); const auto *all_of{schema.try_at("allOf")}; diff --git a/vendor/blaze/src/alterschema/common/duplicate_anyof_branches.h b/vendor/blaze/src/alterschema/common/duplicate_anyof_branches.h index c66e51332..b29468797 100644 --- a/vendor/blaze/src/alterschema/common/duplicate_anyof_branches.h +++ b/vendor/blaze/src/alterschema/common/duplicate_anyof_branches.h @@ -25,7 +25,8 @@ class DuplicateAnyOfBranches final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_APPLICATOR, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); const auto *any_of{schema.try_at("anyOf")}; diff --git a/vendor/blaze/src/alterschema/common/duplicate_enum_values.h b/vendor/blaze/src/alterschema/common/duplicate_enum_values.h index 21907b0bb..2864185c0 100644 --- a/vendor/blaze/src/alterschema/common/duplicate_enum_values.h +++ b/vendor/blaze/src/alterschema/common/duplicate_enum_values.h @@ -26,7 +26,8 @@ class DuplicateEnumValues final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); const auto *enum_value{schema.try_at("enum")}; diff --git a/vendor/blaze/src/alterschema/common/duplicate_required_values.h b/vendor/blaze/src/alterschema/common/duplicate_required_values.h index b4b91d734..160de6344 100644 --- a/vendor/blaze/src/alterschema/common/duplicate_required_values.h +++ b/vendor/blaze/src/alterschema/common/duplicate_required_values.h @@ -23,7 +23,8 @@ class DuplicateRequiredValues final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_VALIDATION, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); const auto *required{schema.try_at("required")}; diff --git a/vendor/blaze/src/alterschema/common/enum_with_type.h b/vendor/blaze/src/alterschema/common/enum_with_type.h index f381f0cf2..2fdb1f987 100644 --- a/vendor/blaze/src/alterschema/common/enum_with_type.h +++ b/vendor/blaze/src/alterschema/common/enum_with_type.h @@ -26,7 +26,8 @@ class EnumWithType final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); const auto *type{schema.try_at("type")}; ONLY_CONTINUE_IF(type); diff --git a/vendor/blaze/src/alterschema/common/equal_numeric_bounds_to_enum.h b/vendor/blaze/src/alterschema/common/equal_numeric_bounds_to_enum.h index 50224471e..d795cee43 100644 --- a/vendor/blaze/src/alterschema/common/equal_numeric_bounds_to_enum.h +++ b/vendor/blaze/src/alterschema/common/equal_numeric_bounds_to_enum.h @@ -23,9 +23,14 @@ class EqualNumericBoundsToEnum final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_0}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_0, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); + // The rewrite drops `type`, which is what makes a sibling `nullable` take + // effect, so null would stop being a permitted value + ONLY_CONTINUE_IF(!is_nullable(schema, vocabularies)); + const auto *type{schema.try_at("type")}; ONLY_CONTINUE_IF( type && type->is_string() && diff --git a/vendor/blaze/src/alterschema/common/exclusive_bounds_false_drop.h b/vendor/blaze/src/alterschema/common/exclusive_bounds_false_drop.h index 04c0c12bf..76b587414 100644 --- a/vendor/blaze/src/alterschema/common/exclusive_bounds_false_drop.h +++ b/vendor/blaze/src/alterschema/common/exclusive_bounds_false_drop.h @@ -20,7 +20,8 @@ class ExclusiveBoundsFalseDrop final : public SchemaTransformRule { ONLY_CONTINUE_IF(vocabularies.contains_any( {SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); const auto *type{schema.try_at("type")}; diff --git a/vendor/blaze/src/alterschema/common/flatten_nested_allof.h b/vendor/blaze/src/alterschema/common/flatten_nested_allof.h index 03d644f5f..2567543fb 100644 --- a/vendor/blaze/src/alterschema/common/flatten_nested_allof.h +++ b/vendor/blaze/src/alterschema/common/flatten_nested_allof.h @@ -24,7 +24,8 @@ class FlattenNestedAllOf final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_APPLICATOR, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object() && schema.defines(KEYWORD) && schema.at(KEYWORD).is_array()); diff --git a/vendor/blaze/src/alterschema/common/flatten_nested_anyof.h b/vendor/blaze/src/alterschema/common/flatten_nested_anyof.h index da7cf45ac..0dc5480b9 100644 --- a/vendor/blaze/src/alterschema/common/flatten_nested_anyof.h +++ b/vendor/blaze/src/alterschema/common/flatten_nested_anyof.h @@ -24,7 +24,8 @@ class FlattenNestedAnyOf final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_APPLICATOR, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object() && schema.defines(KEYWORD) && schema.at(KEYWORD).is_array()); diff --git a/vendor/blaze/src/alterschema/common/maximum_real_for_integer.h b/vendor/blaze/src/alterschema/common/maximum_real_for_integer.h index 7cf8ee1e4..d93ce7b79 100644 --- a/vendor/blaze/src/alterschema/common/maximum_real_for_integer.h +++ b/vendor/blaze/src/alterschema/common/maximum_real_for_integer.h @@ -27,7 +27,8 @@ class MaximumRealForInteger final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); const auto *type{schema.try_at("type")}; diff --git a/vendor/blaze/src/alterschema/common/minimum_real_for_integer.h b/vendor/blaze/src/alterschema/common/minimum_real_for_integer.h index a97722e07..9bed43055 100644 --- a/vendor/blaze/src/alterschema/common/minimum_real_for_integer.h +++ b/vendor/blaze/src/alterschema/common/minimum_real_for_integer.h @@ -27,7 +27,8 @@ class MinimumRealForInteger final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); const auto *type{schema.try_at("type")}; diff --git a/vendor/blaze/src/alterschema/common/non_applicable_enum_validation_keywords.h b/vendor/blaze/src/alterschema/common/non_applicable_enum_validation_keywords.h index 0a2e048d5..b56733ce3 100644 --- a/vendor/blaze/src/alterschema/common/non_applicable_enum_validation_keywords.h +++ b/vendor/blaze/src/alterschema/common/non_applicable_enum_validation_keywords.h @@ -28,7 +28,8 @@ class NonApplicableEnumValidationKeywords final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1_HYPER}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1_HYPER, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object() && !schema.defines("type")); const auto *enum_value{schema.try_at("enum")}; diff --git a/vendor/blaze/src/alterschema/common/non_applicable_type_specific_keywords.h b/vendor/blaze/src/alterschema/common/non_applicable_type_specific_keywords.h index c9d12c906..67f79198a 100644 --- a/vendor/blaze/src/alterschema/common/non_applicable_type_specific_keywords.h +++ b/vendor/blaze/src/alterschema/common/non_applicable_type_specific_keywords.h @@ -32,7 +32,8 @@ class NonApplicableTypeSpecificKeywords final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_0, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_0_HYPER}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_0_HYPER, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && (type_value != nullptr) && is_known_type_form(*type_value, vocabularies) ? parse_schema_type(*type_value) @@ -46,7 +47,8 @@ class NonApplicableTypeSpecificKeywords final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1})) { + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})) { const auto *enum_value{schema.try_at("enum")}; if ((enum_value != nullptr) && enum_value->is_array()) { for (const auto &entry : enum_value->as_array()) { diff --git a/vendor/blaze/src/alterschema/common/oneof_to_anyof_disjoint_types.h b/vendor/blaze/src/alterschema/common/oneof_to_anyof_disjoint_types.h index e5c1b359f..810b58a44 100644 --- a/vendor/blaze/src/alterschema/common/oneof_to_anyof_disjoint_types.h +++ b/vendor/blaze/src/alterschema/common/oneof_to_anyof_disjoint_types.h @@ -24,7 +24,8 @@ class OneOfToAnyOfDisjointTypes final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_APPLICATOR, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); const auto *oneof_value{schema.try_at(KEYWORD)}; @@ -38,7 +39,8 @@ class OneOfToAnyOfDisjointTypes final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1})}; + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})}; const auto has_const_vocabulary{vocabularies.contains_any( {SchemaVocabularies::Known::JSON_SCHEMA_2020_12_VALIDATION, @@ -60,8 +62,11 @@ class OneOfToAnyOfDisjointTypes final : public SchemaTransformRule { const auto has_enum{(enum_value != nullptr) && enum_value->is_array()}; if (type_value != nullptr) { - const auto branch_types{parse_schema_type(*type_value)}; + auto branch_types{parse_schema_type(*type_value)}; ONLY_CONTINUE_IF(branch_types.any()); + if (is_nullable(branch, vocabularies)) { + branch_types.set(std::to_underlying(JSON::Type::Null)); + } type_sets.push_back(branch_types); } else if ((const_value != nullptr) && !has_enum) { JSON::TypeSet branch_types; diff --git a/vendor/blaze/src/alterschema/common/required_properties_in_properties.h b/vendor/blaze/src/alterschema/common/required_properties_in_properties.h index dd7a3299f..e6b8b2bf1 100644 --- a/vendor/blaze/src/alterschema/common/required_properties_in_properties.h +++ b/vendor/blaze/src/alterschema/common/required_properties_in_properties.h @@ -29,7 +29,8 @@ class RequiredPropertiesInProperties final : public SchemaTransformRule { vocabularies.contains_any( {SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4})) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})) && schema.is_object()); const auto *required{schema.try_at("required")}; @@ -68,7 +69,8 @@ class RequiredPropertiesInProperties final : public SchemaTransformRule { for (const auto &location : result.locations) { const auto &property{ schema.at("required").at(location.at(1).to_index()).to_string()}; - schema.at("properties").assign(property, sourcemeta::core::JSON{true}); + schema.at("properties") + .assign(property, sourcemeta::core::JSON::make_object()); } } diff --git a/vendor/blaze/src/alterschema/common/unknown_local_ref.h b/vendor/blaze/src/alterschema/common/unknown_local_ref.h index 66a5fa3f8..ae7db851e 100644 --- a/vendor/blaze/src/alterschema/common/unknown_local_ref.h +++ b/vendor/blaze/src/alterschema/common/unknown_local_ref.h @@ -29,7 +29,8 @@ class UnknownLocalRef final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object() && schema.defines(KEYWORD) && schema.at(KEYWORD).is_string()); diff --git a/vendor/blaze/src/alterschema/common/unnecessary_allof_ref_wrapper_draft.h b/vendor/blaze/src/alterschema/common/unnecessary_allof_ref_wrapper_draft.h index a90af79ea..30294d5e7 100644 --- a/vendor/blaze/src/alterschema/common/unnecessary_allof_ref_wrapper_draft.h +++ b/vendor/blaze/src/alterschema/common/unnecessary_allof_ref_wrapper_draft.h @@ -19,7 +19,8 @@ class UnnecessaryAllOfRefWrapperDraft final : public SchemaTransformRule { ONLY_CONTINUE_IF(vocabularies.contains_any( {SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object() && schema.size() == 1); const auto *all_of{schema.try_at("allOf")}; ONLY_CONTINUE_IF(all_of && all_of->is_array()); diff --git a/vendor/blaze/src/alterschema/common/unsatisfiable_drop_validation.h b/vendor/blaze/src/alterschema/common/unsatisfiable_drop_validation.h index 0fa44de51..7fed6c34a 100644 --- a/vendor/blaze/src/alterschema/common/unsatisfiable_drop_validation.h +++ b/vendor/blaze/src/alterschema/common/unsatisfiable_drop_validation.h @@ -22,10 +22,24 @@ class UnsatisfiableDropValidation final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_APPLICATOR, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); + // In Draft 7 and older dialects, a `$ref` suppresses its siblings, so the + // negation this reads is itself ignored and there is nothing to drop + if (vocabularies.contains_any( + {SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})) { + ONLY_CONTINUE_IF(!schema.defines("$ref")); + } + const bool is_draft_3{vocabularies.contains_any( {SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER})}; diff --git a/vendor/blaze/src/alterschema/common/unsatisfiable_in_place_applicator_type.h b/vendor/blaze/src/alterschema/common/unsatisfiable_in_place_applicator_type.h index 8f800535e..d37d99824 100644 --- a/vendor/blaze/src/alterschema/common/unsatisfiable_in_place_applicator_type.h +++ b/vendor/blaze/src/alterschema/common/unsatisfiable_in_place_applicator_type.h @@ -18,6 +18,8 @@ class UnsatisfiableInPlaceApplicatorType final : public SchemaTransformRule { const sourcemeta::core::SchemaResolver &) const -> SchemaTransformRule::Result override { ONLY_CONTINUE_IF(schema.is_object() && schema.defines("type")); + // The OpenAPI 3.0 Schema Object is deliberately absent, as the branch this + // rewrites to the `false` schema has no spelling in that dialect ONLY_CONTINUE_IF(vocabularies.contains_any( {SchemaVocabularies::Known::JSON_SCHEMA_2020_12_VALIDATION, SchemaVocabularies::Known::JSON_SCHEMA_2019_09_VALIDATION, diff --git a/vendor/blaze/src/alterschema/linter/conflicting_readonly_writeonly.h b/vendor/blaze/src/alterschema/linter/conflicting_readonly_writeonly.h index 976dd3db2..a575707dd 100644 --- a/vendor/blaze/src/alterschema/linter/conflicting_readonly_writeonly.h +++ b/vendor/blaze/src/alterschema/linter/conflicting_readonly_writeonly.h @@ -19,7 +19,8 @@ class ConflictingReadOnlyWriteOnly final : public SchemaTransformRule { ONLY_CONTINUE_IF(vocabularies.contains_any( {SchemaVocabularies::Known::JSON_SCHEMA_2020_12_META_DATA, SchemaVocabularies::Known::JSON_SCHEMA_2019_09_META_DATA, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); const auto *read_only{schema.try_at("readOnly")}; const auto *write_only{schema.try_at("writeOnly")}; diff --git a/vendor/blaze/src/alterschema/linter/description_trailing_period.h b/vendor/blaze/src/alterschema/linter/description_trailing_period.h index 35d2c242e..f2e6b11ab 100644 --- a/vendor/blaze/src/alterschema/linter/description_trailing_period.h +++ b/vendor/blaze/src/alterschema/linter/description_trailing_period.h @@ -26,7 +26,8 @@ class DescriptionTrailingPeriod final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); ONLY_CONTINUE_IF(schema.defines("description")); ONLY_CONTINUE_IF(schema.at("description").is_string()); diff --git a/vendor/blaze/src/alterschema/linter/description_trim.h b/vendor/blaze/src/alterschema/linter/description_trim.h index 825bd8e72..dc1f8d4b0 100644 --- a/vendor/blaze/src/alterschema/linter/description_trim.h +++ b/vendor/blaze/src/alterschema/linter/description_trim.h @@ -26,7 +26,8 @@ class DescriptionTrim final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); ONLY_CONTINUE_IF(schema.defines("description")); ONLY_CONTINUE_IF(schema.at("description").is_string()); diff --git a/vendor/blaze/src/alterschema/linter/forbid_empty_enum.h b/vendor/blaze/src/alterschema/linter/forbid_empty_enum.h index 21c5f09a3..3d5806c69 100644 --- a/vendor/blaze/src/alterschema/linter/forbid_empty_enum.h +++ b/vendor/blaze/src/alterschema/linter/forbid_empty_enum.h @@ -22,7 +22,8 @@ class ForbidEmptyEnum final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_VALIDATION, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object() && !schema.defines("not")); const auto *enum_value{schema.try_at("enum")}; diff --git a/vendor/blaze/src/alterschema/linter/invalid_external_ref.h b/vendor/blaze/src/alterschema/linter/invalid_external_ref.h index 3bbebeadb..a5f08c09f 100644 --- a/vendor/blaze/src/alterschema/linter/invalid_external_ref.h +++ b/vendor/blaze/src/alterschema/linter/invalid_external_ref.h @@ -22,7 +22,8 @@ class InvalidExternalRef final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object() && schema.defines(KEYWORD) && schema.at(KEYWORD).is_string()); diff --git a/vendor/blaze/src/alterschema/linter/items_schema_default.h b/vendor/blaze/src/alterschema/linter/items_schema_default.h index 3eeec498d..6169d3768 100644 --- a/vendor/blaze/src/alterschema/linter/items_schema_default.h +++ b/vendor/blaze/src/alterschema/linter/items_schema_default.h @@ -32,12 +32,22 @@ class ItemsSchemaDefault final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1_HYPER}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1_HYPER, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object() && schema.defines(KEYWORD) && ((schema.at(KEYWORD).is_boolean() && schema.at(KEYWORD).to_boolean()) || (schema.at(KEYWORD).is_object() && schema.at(KEYWORD).empty()))); ONLY_CONTINUE_IF(!frame.has_references_through( location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); + + // OpenAPI 3.0 asks that `items` be present whenever `type` names `array`, + // so the keyword has to stay however little it constrains + if (vocabularies.contains(SchemaVocabularies::Known::OPENAPI_3_0_BASE)) { + const auto *type{schema.try_at("type")}; + ONLY_CONTINUE_IF(!(type != nullptr && type->is_string() && + type->to_string() == "array")); + } + return applies_to_keywords(KEYWORD); } diff --git a/vendor/blaze/src/alterschema/linter/multiple_of_default.h b/vendor/blaze/src/alterschema/linter/multiple_of_default.h index f45bb9964..39b35dbbc 100644 --- a/vendor/blaze/src/alterschema/linter/multiple_of_default.h +++ b/vendor/blaze/src/alterschema/linter/multiple_of_default.h @@ -22,7 +22,8 @@ class MultipleOfDefault final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_VALIDATION, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); const auto *type{schema.try_at("type")}; diff --git a/vendor/blaze/src/alterschema/linter/pattern_non_ecma_regex.h b/vendor/blaze/src/alterschema/linter/pattern_non_ecma_regex.h index 7a9a2574c..332ce9611 100644 --- a/vendor/blaze/src/alterschema/linter/pattern_non_ecma_regex.h +++ b/vendor/blaze/src/alterschema/linter/pattern_non_ecma_regex.h @@ -33,7 +33,8 @@ class PatternNonEcmaRegex final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_0, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_0_HYPER})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_0_HYPER, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); const auto *pattern_value{schema.try_at("pattern")}; diff --git a/vendor/blaze/src/alterschema/linter/properties_default.h b/vendor/blaze/src/alterschema/linter/properties_default.h index 41f3ee018..0cb7246dd 100644 --- a/vendor/blaze/src/alterschema/linter/properties_default.h +++ b/vendor/blaze/src/alterschema/linter/properties_default.h @@ -29,7 +29,8 @@ class PropertiesDefault final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1_HYPER}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1_HYPER, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); const auto *properties{schema.try_at("properties")}; diff --git a/vendor/blaze/src/alterschema/linter/simple_properties_identifiers.h b/vendor/blaze/src/alterschema/linter/simple_properties_identifiers.h index e9f9871f9..a060062ea 100644 --- a/vendor/blaze/src/alterschema/linter/simple_properties_identifiers.h +++ b/vendor/blaze/src/alterschema/linter/simple_properties_identifiers.h @@ -30,7 +30,8 @@ class SimplePropertiesIdentifiers final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1_HYPER})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1_HYPER, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); const auto *properties{schema.try_at("properties")}; ONLY_CONTINUE_IF(properties && properties->is_object() && diff --git a/vendor/blaze/src/alterschema/linter/title_description_equal.h b/vendor/blaze/src/alterschema/linter/title_description_equal.h index c0d31369d..7fd657d95 100644 --- a/vendor/blaze/src/alterschema/linter/title_description_equal.h +++ b/vendor/blaze/src/alterschema/linter/title_description_equal.h @@ -26,7 +26,8 @@ class TitleDescriptionEqual final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); ONLY_CONTINUE_IF(schema.defines("title") && schema.defines("description")); ONLY_CONTINUE_IF(schema.at("title").is_string() && diff --git a/vendor/blaze/src/alterschema/linter/title_trailing_period.h b/vendor/blaze/src/alterschema/linter/title_trailing_period.h index 06df64fb3..a667960ba 100644 --- a/vendor/blaze/src/alterschema/linter/title_trailing_period.h +++ b/vendor/blaze/src/alterschema/linter/title_trailing_period.h @@ -26,7 +26,8 @@ class TitleTrailingPeriod final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); ONLY_CONTINUE_IF(schema.defines("title")); ONLY_CONTINUE_IF(schema.at("title").is_string()); diff --git a/vendor/blaze/src/alterschema/linter/title_trim.h b/vendor/blaze/src/alterschema/linter/title_trim.h index 8b779aaa1..e7ca5becd 100644 --- a/vendor/blaze/src/alterschema/linter/title_trim.h +++ b/vendor/blaze/src/alterschema/linter/title_trim.h @@ -25,7 +25,8 @@ class TitleTrim final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); ONLY_CONTINUE_IF(schema.defines("title")); ONLY_CONTINUE_IF(schema.at("title").is_string()); diff --git a/vendor/blaze/src/alterschema/linter/top_level_description.h b/vendor/blaze/src/alterschema/linter/top_level_description.h index 7480e0c59..564ed9abd 100644 --- a/vendor/blaze/src/alterschema/linter/top_level_description.h +++ b/vendor/blaze/src/alterschema/linter/top_level_description.h @@ -27,7 +27,8 @@ class TopLevelDescription final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); const auto *description{schema.try_at("description")}; if ((description != nullptr) && description->is_string() && diff --git a/vendor/blaze/src/alterschema/linter/top_level_title.h b/vendor/blaze/src/alterschema/linter/top_level_title.h index face2a284..71f1457f9 100644 --- a/vendor/blaze/src/alterschema/linter/top_level_title.h +++ b/vendor/blaze/src/alterschema/linter/top_level_title.h @@ -27,7 +27,8 @@ class TopLevelTitle final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_3_HYPER, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_2, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_1, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); const auto *title{schema.try_at("title")}; if ((title != nullptr) && title->is_string() && title->empty()) { diff --git a/vendor/blaze/src/alterschema/linter/unknown_format_prefix.h b/vendor/blaze/src/alterschema/linter/unknown_format_prefix.h index 356c2e9ff..0185869f4 100644 --- a/vendor/blaze/src/alterschema/linter/unknown_format_prefix.h +++ b/vendor/blaze/src/alterschema/linter/unknown_format_prefix.h @@ -72,6 +72,9 @@ class UnknownFormatPrefix final : public SchemaTransformRule { vocabularies.contains(Known::JSON_SCHEMA_2020_12_FORMAT_ASSERTION)) { return &DRAFT_2020_12_FORMATS; } + if (vocabularies.contains(Known::OPENAPI_3_0_BASE)) { + return &OPENAPI_3_0_FORMATS; + } return nullptr; } @@ -104,6 +107,13 @@ class UnknownFormatPrefix final : public SchemaTransformRule { "iri", "iri-reference", "uuid", "uri-template", "json-pointer", "relative-json-pointer", "regex"}; + // The OpenAPI 3.0 Schema Object relies on the formats of the JSON Schema + // revision it is drawn from, Draft Wright-00, and adds a few of its own + // NOLINTNEXTLINE(cert-err58-cpp,bugprone-throwing-static-initialization) + static inline const std::unordered_set OPENAPI_3_0_FORMATS{ + "date-time", "email", "hostname", "ipv4", "ipv6", + "uri", "uriref", "int32", "int64", "float", + "double", "byte", "binary", "date", "password"}; static inline const std::unordered_set // NOLINTNEXTLINE(cert-err58-cpp,bugprone-throwing-static-initialization) DRAFT_2020_12_FORMATS{ diff --git a/vendor/blaze/src/alterschema/linter/unnecessary_allof_wrapper.h b/vendor/blaze/src/alterschema/linter/unnecessary_allof_wrapper.h index 3e49d26de..553372c0c 100644 --- a/vendor/blaze/src/alterschema/linter/unnecessary_allof_wrapper.h +++ b/vendor/blaze/src/alterschema/linter/unnecessary_allof_wrapper.h @@ -22,7 +22,8 @@ class UnnecessaryAllOfWrapper final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_APPLICATOR, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4})); + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE})); ONLY_CONTINUE_IF(schema.is_object()); const auto *all_of_value{schema.try_at(KEYWORD)}; @@ -68,7 +69,8 @@ class UnnecessaryAllOfWrapper final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_VALIDATION, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) ? parse_schema_type(*parent_type_value) : JSON::TypeSet{}}; @@ -110,6 +112,15 @@ class UnnecessaryAllOfWrapper final : public SchemaTransformRule { const auto &keyword{keyword_entry.first}; const auto &metadata{walker(keyword, vocabularies)}; + // In OpenAPI 3.0, `nullable` widens the `type` that sits next to it, so + // moving either one out from under the other changes what the branch + // and the parent each admit + if ((keyword == "nullable" && is_nullable(entry, vocabularies)) || + (keyword == "type" && (is_nullable(schema, vocabularies) || + is_nullable(entry, vocabularies)))) { + return false; + } + if (elevated.contains(keyword) || (schema.defines(keyword) && schema.at(keyword) != keyword_entry.second)) { @@ -251,6 +262,11 @@ class UnnecessaryAllOfWrapper final : public SchemaTransformRule { return !entry.defines("id"); } + // The OpenAPI 3.0 Schema Object has no identifier keyword at all + if (vocabularies.contains(SchemaVocabularies::Known::OPENAPI_3_0_BASE)) { + return true; + } + return false; } }; diff --git a/vendor/blaze/src/alterschema/linter/unsatisfiable_min_properties.h b/vendor/blaze/src/alterschema/linter/unsatisfiable_min_properties.h index 3f07a1eeb..79faf1734 100644 --- a/vendor/blaze/src/alterschema/linter/unsatisfiable_min_properties.h +++ b/vendor/blaze/src/alterschema/linter/unsatisfiable_min_properties.h @@ -23,7 +23,8 @@ class UnsatisfiableMinProperties final : public SchemaTransformRule { SchemaVocabularies::Known::JSON_SCHEMA_2019_09_VALIDATION, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_7, SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_6, - SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4}) && + SchemaVocabularies::Known::JSON_SCHEMA_DRAFT_4, + SchemaVocabularies::Known::OPENAPI_3_0_BASE}) && schema.is_object()); const auto *min_properties{schema.try_at("minProperties")}; diff --git a/vendor/blaze/src/alterschema/linter/valid_default.h b/vendor/blaze/src/alterschema/linter/valid_default.h index 792b3f33e..bb5da8bba 100644 --- a/vendor/blaze/src/alterschema/linter/valid_default.h +++ b/vendor/blaze/src/alterschema/linter/valid_default.h @@ -24,13 +24,14 @@ class ValidDefault final : public SchemaTransformRule { {Known::JSON_SCHEMA_2020_12_META_DATA, Known::JSON_SCHEMA_2019_09_META_DATA, Known::JSON_SCHEMA_DRAFT_7, Known::JSON_SCHEMA_DRAFT_6, Known::JSON_SCHEMA_DRAFT_4, - Known::JSON_SCHEMA_DRAFT_3, Known::JSON_SCHEMA_DRAFT_3_HYPER}) && + Known::JSON_SCHEMA_DRAFT_3, Known::JSON_SCHEMA_DRAFT_3_HYPER, + Known::OPENAPI_3_0_BASE}) && schema.is_object() && schema.defines("default")); if (vocabularies.contains_any( {Known::JSON_SCHEMA_DRAFT_7, Known::JSON_SCHEMA_DRAFT_6, Known::JSON_SCHEMA_DRAFT_4, Known::JSON_SCHEMA_DRAFT_3, - Known::JSON_SCHEMA_DRAFT_3_HYPER})) { + Known::JSON_SCHEMA_DRAFT_3_HYPER, Known::OPENAPI_3_0_BASE})) { ONLY_CONTINUE_IF(!schema.defines("$ref")); } diff --git a/vendor/blaze/src/canonicalizer/canonicalize.cc b/vendor/blaze/src/canonicalizer/canonicalize.cc index 55bf51853..c8809afc8 100644 --- a/vendor/blaze/src/canonicalizer/canonicalize.cc +++ b/vendor/blaze/src/canonicalizer/canonicalize.cc @@ -246,20 +246,31 @@ auto apply(const std::vector &rules, sourcemeta::core::JSON &schema, } } -auto is_draft3(const core::SchemaBaseDialect base_dialect) -> bool { +/// The drafts that spell the identifier `id` and let it nest anywhere, so +/// that a subschema can change the base URI the references around it resolve +/// against. Draft 6 renamed the keyword to `$id` and the rules there differ. +/// +/// Erasing an identifier is only worth doing where the graph form follows, +/// since the form is what cannot carry one. These must therefore name exactly +/// the dialects `profile_for` covers: a dialect that lost its identifiers +/// without being lifted would keep every nested document it had while no +/// longer being able to address them. That is why Draft 4 hyper-schema is +/// absent, as it is there +auto has_nested_id(const core::SchemaBaseDialect base_dialect) -> bool { return base_dialect == core::SchemaBaseDialect::JSON_SCHEMA_DRAFT_3 || - base_dialect == core::SchemaBaseDialect::JSON_SCHEMA_DRAFT_3_HYPER; + base_dialect == core::SchemaBaseDialect::JSON_SCHEMA_DRAFT_3_HYPER || + base_dialect == core::SchemaBaseDialect::JSON_SCHEMA_DRAFT_4; } -/// Remove every Draft 3 identifier, including anchors and the identifier of -/// the root. Every reference is first resolved while the frame still knows -/// the identifiers, and rewritten into a form that does not depend on any of -/// them: a JSON Pointer into this document when the destination is local, or -/// the absolute URI when it is not. Only then are the identifiers erased, so -/// no reference can lose the base it was resolved against. +/// Remove every `id`, including anchors and the identifier of the root. Every +/// reference is first resolved while the frame still knows the identifiers, +/// and rewritten into a form that does not depend on any of them: a JSON +/// Pointer into this document when the destination is local, or the absolute +/// URI when it is not. Only then are the identifiers erased, so no reference +/// can lose the base it was resolved against. /// -/// This only applies to documents that are Draft 3 throughout. A document of -/// another dialect may embed a Draft 3 resource and reference it by its +/// This only applies to documents that use `id` throughout. A document of +/// another dialect may embed such a resource and reference it by its /// identifier from outside, with a reference this pass must not rewrite, so /// such documents are left untouched auto eliminate_identifiers(sourcemeta::core::JSON &schema, @@ -285,7 +296,7 @@ auto eliminate_identifiers(sourcemeta::core::JSON &schema, if (frame.any_subschema( [](const core::SchemaFrame::Location &location) -> bool { - return !is_draft3(location.base_dialect); + return !has_nested_id(location.base_dialect); })) { return; } @@ -374,11 +385,83 @@ auto entry_number(const sourcemeta::core::JSON &reference) return static_cast(std::stoull(suffix)); } +/// How the graph form is spelled in a given dialect: the form is the same +/// everywhere, only the keywords and what the dialect allows differ +struct Profile { + /// The keyword a conjunction is written with + sourcemeta::core::JSON::String wrapper; + /// Keywords whose value is an object whose members are subschemas + std::set mappings; + /// Keywords whose value is a single subschema + std::set singles; + /// Keywords whose value is a subschema or an array of them + std::set branches; + /// Keywords whose arrays say nothing new by naming the same entry twice + std::set unique_branches; + /// Whether requiredness is a marker beside the subschema it applies to, as + /// in Draft 3, rather than a list of names on the object, as from Draft 4 on + bool property_marker; + /// Whether a boolean standing in for a subschema can be an entry. From + /// Draft 4 on the values of `definitions` have to be schemas, and a boolean + /// is not one, so there it stays where it is + bool boolean_nodes; +}; + +/// Draft 3 states a conjunction with `extends`, a disjunction as an array of +/// subschemas under `type`, and a negation with `disallow` +auto draft3_profile() -> const Profile & { + static const Profile PROFILE{ + .wrapper = "extends", + .mappings = {"properties", "patternProperties", "dependencies"}, + .singles = {"additionalProperties", "additionalItems"}, + .branches = {"items", "type", "extends", "disallow"}, + .unique_branches = {"type", "extends", "disallow"}, + .property_marker = true, + .boolean_nodes = true}; + return PROFILE; +} + +/// Draft 4 replaces those three with `allOf`, `anyOf`, `oneOf` and `not`. Its +/// `type` only ever names types, so unlike Draft 3 it holds no subschema, and +/// its requiredness is a list of names on the object rather than a marker +auto draft4_profile() -> const Profile & { + static const Profile PROFILE{ + .wrapper = "allOf", + .mappings = {"properties", "patternProperties", "dependencies"}, + .singles = {"additionalProperties", "additionalItems", "not"}, + .branches = {"items", "allOf", "anyOf", "oneOf"}, + // `oneOf` counts how many branches match, so naming the same entry + // twice is not the same as naming it once: two identical branches + // never match, one always can + .unique_branches = {"allOf", "anyOf"}, + .property_marker = false, + .boolean_nodes = false}; + return PROFILE; +} + +/// The profile for a dialect, when the graph form covers it at all. Draft 3 +/// hyper-schema shares the Draft 3 profile: by the time this runs the rules +/// have dropped the keywords its vocabulary adds, none of which takes part +/// in whether an instance is valid. Draft 4 hyper-schema has no such rule +/// yet, so its `links` would be lifted as though they were subschemas +auto profile_for(const core::SchemaBaseDialect base_dialect) + -> const Profile * { + switch (base_dialect) { + case core::SchemaBaseDialect::JSON_SCHEMA_DRAFT_3: + case core::SchemaBaseDialect::JSON_SCHEMA_DRAFT_3_HYPER: + return &draft3_profile(); + case core::SchemaBaseDialect::JSON_SCHEMA_DRAFT_4: + return &draft4_profile(); + default: + return nullptr; + } +} + /// The reference an entry amounts to, when the entry is nothing but a -/// reference: either on its own, or behind the one-element `extends` that -/// this pass leaves in place of a lifted subschema. Such a subschema is an -/// edge of the graph rather than a node of it -auto edge_reference(const sourcemeta::core::JSON &body) +/// reference: either on its own, or behind the one-element wrapper that this +/// pass leaves in place of a lifted subschema. Such a subschema is an edge of +/// the graph rather than a node of it +auto edge_reference(const sourcemeta::core::JSON &body, const Profile &profile) -> const sourcemeta::core::JSON * { if (!body.is_object() || body.size() != 1) { return nullptr; @@ -388,11 +471,11 @@ auto edge_reference(const sourcemeta::core::JSON &body) return &body.at("$ref"); } - if (!body.defines("extends")) { + if (!body.defines(profile.wrapper)) { return nullptr; } - const auto &branches{body.at("extends")}; + const auto &branches{body.at(profile.wrapper)}; if (!branches.is_array() || branches.size() != 1) { return nullptr; } @@ -408,20 +491,25 @@ auto edge_reference(const sourcemeta::core::JSON &body) /// Whether the given body is an edge rather than a node. Only a reference /// that stays inside the document can reach an entry, so one that leaves it /// becomes an entry of its own and every edge really is an edge of the graph -auto is_edge(const sourcemeta::core::JSON &body) -> bool { - const auto *reference{edge_reference(body)}; +auto is_edge(const sourcemeta::core::JSON &body, const Profile &profile) + -> bool { + const auto *reference{edge_reference(body, profile)}; return reference != nullptr && reference->is_string() && reference->to_string().starts_with('#'); } /// What a subschema says, with the keywords that carry the graph itself taken -/// out. `definitions` holds other nodes rather than part of this one, and a -/// `required` marker belongs to the parent `properties` -auto without_containers(sourcemeta::core::JSON body) -> sourcemeta::core::JSON { +/// out. `definitions` holds other nodes rather than part of this one, and +/// where requiredness is a marker it belongs to the parent `properties` +/// rather than to the subschema it sits on +auto without_containers(sourcemeta::core::JSON body, const Profile &profile) + -> sourcemeta::core::JSON { if (body.is_object()) { body.erase("$schema"); body.erase("definitions"); - body.erase("required"); + if (profile.property_marker) { + body.erase("required"); + } } return body; @@ -439,22 +527,12 @@ auto without_containers(sourcemeta::core::JSON body) -> sourcemeta::core::JSON { /// /// Members are read in key order so that the result never depends on the order /// an object happens to store them in -auto reference_slots(const sourcemeta::core::JSON &body) +auto reference_slots(const sourcemeta::core::JSON &body, const Profile &profile) -> std::vector { - static const std::set MAPPINGS{ - "properties", "patternProperties", "dependencies"}; - static const std::set SINGLES{ - "additionalProperties", "additionalItems"}; - // `items` holds either one subschema or a tuple of them, and the three - // Draft 3 keywords that take branches hold an array once the rules have run, - // though hyper-schema can leave a lone subschema behind - static const std::set BRANCHES{ - "items", "type", "extends", "disallow"}; - std::vector result; - const auto collect{[&result](const sourcemeta::core::JSON ¤t, - const core::Pointer &position, - const auto &self) -> void { + const auto collect{[&result, &profile](const sourcemeta::core::JSON ¤t, + const core::Pointer &position, + const auto &self) -> void { if (!current.is_object()) { return; } @@ -472,7 +550,7 @@ auto reference_slots(const sourcemeta::core::JSON &body) if (value.is_string()) { result.push_back(position.concat(key)); } - } else if (MAPPINGS.contains(key) && value.is_object()) { + } else if (profile.mappings.contains(key) && value.is_object()) { std::vector names; names.reserve(value.size()); for (const auto &member : value.as_object()) { @@ -483,9 +561,9 @@ auto reference_slots(const sourcemeta::core::JSON &body) for (const auto &name : names) { self(value.at(name), position.concat(key).concat(name), self); } - } else if (SINGLES.contains(key)) { + } else if (profile.singles.contains(key)) { self(value, position.concat(key), self); - } else if (BRANCHES.contains(key)) { + } else if (profile.branches.contains(key)) { if (value.is_array()) { for (std::size_t index = 0; index < value.size(); index++) { self(value.at(index), @@ -519,6 +597,7 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, return; } + const Profile *profile{nullptr}; std::vector nodes; // Every reference the document declares, before edges are followed through std::vector> links; @@ -533,24 +612,40 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, default_id, core::SchemaFrame::IdentifierMode::Fallback}; - // Hyper-schema comes this far too. Nothing its vocabulary declares takes - // part in whether an instance is valid, so the rules have dropped all of - // it by now, and what is left is Draft 3 proper however the document - // spells its dialect - if (frame.any_subschema( - [](const core::SchemaFrame::Location &location) -> bool { - return !is_draft3(location.base_dialect); - })) { + // Every subschema has to land on the same spelling of the form, and on + // one the form covers at all. Draft 3 and its hyper-schema share a + // profile: by now the rules have dropped everything the hyper-schema + // vocabulary adds, none of which takes part in whether an instance is + // valid + bool unsupported{false}; + frame.for_each_subschema( + [&profile, + &unsupported](const core::SchemaFrame::Location &location) -> void { + const auto *current{profile_for(location.base_dialect)}; + if (current == nullptr || + (profile != nullptr && profile != current)) { + unsupported = true; + } else { + profile = current; + } + }); + + if (unsupported || profile == nullptr) { return; } frame.for_each_subschema( - [&nodes, &schema](const core::SchemaFrame::Location &location) -> void { + [&nodes, &schema, + profile](const core::SchemaFrame::Location &location) -> void { + const auto &body{core::get(schema, location.pointer)}; + if (!profile->boolean_nodes && body.is_boolean()) { + return; + } + // The test runs on what the body would be once the container // keywords are stripped, so that a root already in graph form is // recognised as the wrapper it is - if (is_edge( - without_containers(core::get(schema, location.pointer)))) { + if (is_edge(without_containers(body, *profile), *profile)) { return; } @@ -589,9 +684,8 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, // A reference can target a subschema that is itself an edge, so follow such // a chain through to the node it ultimately reaches static const core::JSON::String REF_KEYWORD{"$ref"}; - static const core::JSON::String EXTENDS_KEYWORD{"extends"}; - const auto resolve{[&nodes, &links](const core::Pointer &start) + const auto resolve{[&nodes, &links, profile](const core::Pointer &start) -> std::optional { auto target{start}; for (std::size_t hop = 0; hop <= links.size(); hop++) { @@ -609,10 +703,10 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, continue; } - const auto wrapped{ - std::ranges::find_if(links, [&target](const auto &entry) -> bool { + const auto wrapped{std::ranges::find_if( + links, [&target, profile](const auto &entry) -> bool { return entry.first == - target.concat({EXTENDS_KEYWORD, + target.concat({profile->wrapper, static_cast(0), REF_KEYWORD}); })}; @@ -666,35 +760,40 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, return result; }}; - const auto link{[](const std::size_t index, - const sourcemeta::core::JSON &target, - const core::Pointer &position) -> sourcemeta::core::JSON { - auto reference{sourcemeta::core::JSON::make_object()}; - reference.assign("$ref", sourcemeta::core::JSON{"#/definitions/" + - std::to_string(index)}); - - // `required` is read by the parent `properties`, and Draft 3 ignores - // the siblings of a `$ref`, so the marker can neither travel into the - // entry nor sit next to the reference. It stays behind, wrapping it - const auto *marker{target.is_object() ? target.try_at("required") - : nullptr}; - // Anywhere but a property entry the marker means nothing at all, so - // a subschema under `items` or `additionalProperties` loses it - const auto under_properties{ - position.size() >= 2 && - position.at(position.size() - 2).is_property() && - position.at(position.size() - 2).to_property() == "properties"}; - if (marker == nullptr || !under_properties) { - return reference; - } + const auto link{ + [profile](const std::size_t index, const sourcemeta::core::JSON &target, + const core::Pointer &position) -> sourcemeta::core::JSON { + auto reference{sourcemeta::core::JSON::make_object()}; + reference.assign("$ref", sourcemeta::core::JSON{"#/definitions/" + + std::to_string(index)}); - auto wrapper{sourcemeta::core::JSON::make_object()}; - wrapper.assign("required", *marker); - auto branches{sourcemeta::core::JSON::make_array()}; - branches.push_back(std::move(reference)); - wrapper.assign("extends", std::move(branches)); - return wrapper; - }}; + // A list of names on the object leaves nothing behind + if (!profile->property_marker) { + return reference; + } + + // A marker is read by the parent `properties`, and these drafts ignore + // the siblings of a `$ref`, so it can neither travel into the entry nor + // sit next to the reference. It stays behind, wrapping it + const auto *marker{target.is_object() ? target.try_at("required") + : nullptr}; + // Anywhere but a property entry the marker means nothing at all, so + // a subschema under `items` or `additionalProperties` loses it + const auto under_properties{ + position.size() >= 2 && + position.at(position.size() - 2).is_property() && + position.at(position.size() - 2).to_property() == "properties"}; + if (marker == nullptr || !under_properties) { + return reference; + } + + auto wrapper{sourcemeta::core::JSON::make_object()}; + wrapper.assign("required", *marker); + auto branches{sourcemeta::core::JSON::make_array()}; + branches.push_back(std::move(reference)); + wrapper.assign(profile->wrapper, std::move(branches)); + return wrapper; + }}; const auto entry_node{resolve(core::Pointer{})}; if (!entry_node.has_value()) { @@ -735,7 +834,9 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, if (body.is_object()) { body.erase("$schema"); - body.erase("required"); + if (profile->property_marker) { + body.erase("required"); + } // Every entry of a `definitions` is a node of its own, so the container // is not part of any body. Leaving it in would make a later pass lift // the same entries again @@ -759,7 +860,7 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, // and the entry itself goes away std::map collapsed; for (const auto &entry : definitions.as_object()) { - const auto *reference{edge_reference(entry.second)}; + const auto *reference{edge_reference(entry.second, *profile)}; if (reference == nullptr) { continue; } @@ -792,9 +893,9 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, } } - const auto rewrite{[&destination, - &renamed](sourcemeta::core::JSON &body) -> void { - for (const auto &slot : reference_slots(body)) { + const auto rewrite{[&destination, &renamed, + profile](sourcemeta::core::JSON &body) -> void { + for (const auto &slot : reference_slots(body, *profile)) { const auto entry{entry_number(core::get(body, slot))}; if (!entry.has_value()) { continue; @@ -836,9 +937,9 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, // not depend on the order an object happens to store its members in. // Reading them by sorted key gives the same answer however the object was // built - const auto targets{[](const sourcemeta::core::JSON &body, - std::vector &result) -> void { - for (const auto &slot : reference_slots(body)) { + const auto targets{[profile](const sourcemeta::core::JSON &body, + std::vector &result) -> void { + for (const auto &slot : reference_slots(body, *profile)) { const auto entry{entry_number(core::get(body, slot))}; if (entry.has_value()) { result.push_back(entry.value()); @@ -849,17 +950,17 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, // Only the references this pass produced are set aside. A reference that // leaves the document names no entry, so it stays part of what the body // says: two entries that point at different documents are not the same - const auto skeleton{ - [](const sourcemeta::core::JSON &body) -> sourcemeta::core::JSON { - auto result{body}; - for (const auto &slot : reference_slots(result)) { - if (entry_number(core::get(result, slot)).has_value()) { - core::set(result, slot, sourcemeta::core::JSON{""}); - } - } + const auto skeleton{[profile](const sourcemeta::core::JSON &body) + -> sourcemeta::core::JSON { + auto result{body}; + for (const auto &slot : reference_slots(result, *profile)) { + if (entry_number(core::get(result, slot)).has_value()) { + core::set(result, slot, sourcemeta::core::JSON{""}); + } + } - return result; - }}; + return result; + }}; std::vector> outgoing{bodies.size()}; std::vector classes(bodies.size(), 0); @@ -933,33 +1034,34 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, position.emplace(walked.at(index), index); } - const auto relabel{[&classes, &position](const sourcemeta::core::JSON &body) - -> sourcemeta::core::JSON { - auto result{body}; - for (const auto &slot : reference_slots(result)) { - const auto entry{entry_number(core::get(result, slot))}; - if (!entry.has_value()) { - continue; - } + const auto relabel{ + [&classes, &position, profile]( + const sourcemeta::core::JSON &body) -> sourcemeta::core::JSON { + auto result{body}; + for (const auto &slot : reference_slots(result, *profile)) { + const auto entry{entry_number(core::get(result, slot))}; + if (!entry.has_value()) { + continue; + } - core::set(result, slot, - sourcemeta::core::JSON{ - "#/definitions/" + - std::to_string(position.at(classes.at(entry.value())))}); - } + core::set(result, slot, + sourcemeta::core::JSON{"#/definitions/" + + std::to_string(position.at( + classes.at(entry.value())))}); + } - return result; - }}; + return result; + }}; // Merging entries can leave a disjunction or a conjunction listing the same - // entry twice, which says nothing new. The rules already drop duplicates in - // these three keywords, but they run before any of this - const auto unique{[](sourcemeta::core::JSON &body) -> void { + // entry twice, which says nothing new. The rules already drop duplicates + // in these keywords, but they run before any of this + const auto unique{[profile](sourcemeta::core::JSON &body) -> void { if (!body.is_object()) { return; } - for (const auto *keyword : {"type", "extends", "disallow"}) { + for (const auto &keyword : profile->unique_branches) { auto *entries{body.try_at(keyword)}; if (entries == nullptr || !entries->is_array()) { continue; @@ -1015,7 +1117,7 @@ auto lift_subschemas(sourcemeta::core::JSON &schema, reference.assign("$ref", sourcemeta::core::JSON{"#/definitions/" + std::to_string(entry_point)}); wrapper.push_back(std::move(reference)); - result.assign("extends", std::move(wrapper)); + result.assign(profile->wrapper, std::move(wrapper)); result.assign("definitions", std::move(definitions)); schema.into(std::move(result)); } diff --git a/vendor/blaze/src/codegen/codegen_default_compiler.h b/vendor/blaze/src/codegen/codegen_default_compiler.h index 4559bc13b..44204523e 100644 --- a/vendor/blaze/src/codegen/codegen_default_compiler.h +++ b/vendor/blaze/src/codegen/codegen_default_compiler.h @@ -13,12 +13,14 @@ // We do not check vocabularies here because the canonicaliser ensures // we never get an official keyword when its vocabulary is not present +// Every shape already allows `$defs`. `definitions` is the same container +// under the spelling Drafts 4 to 7 use, so allow it everywhere too // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define ONLY_WHITELIST_KEYWORDS(schema, subschema, pointer, ...) \ { \ static const std::unordered_set allowed{__VA_ARGS__}; \ for (const auto &entry : (subschema).as_object()) { \ - if (!allowed.contains(entry.first)) { \ + if (entry.first != "definitions" && !allowed.contains(entry.first)) { \ throw sourcemeta::blaze::CodegenUnsupportedKeywordError( \ (schema), (pointer), entry.first, \ "Unsupported keyword in subschema"); \ diff --git a/vendor/blaze/src/compiler/compile.cc b/vendor/blaze/src/compiler/compile.cc index ca9aa0dee..32dbdded6 100644 --- a/vendor/blaze/src/compiler/compile.cc +++ b/vendor/blaze/src/compiler/compile.cc @@ -1034,15 +1034,30 @@ auto compile(const Context &context, const SchemaContext &schema_context, .recompose_without_fragment() .value_or("") : schema_context.base.recompose_without_fragment().value_or("")}; + const auto new_vocabularies{ + entry.has_value() + ? context.frame.vocabularies(entry.value().get(), context.resolver) + : schema_context.vocabularies}; + + // The root check on dialects without boolean schemas cannot see a boolean + // reference target, as a target compiles with the pointer of wherever it + // sits rather than as the root of a resource. Only a reference lands here + // with a URI: a boolean a keyword admits in place of a schema comes in + // through the suffixes instead, so it stays out of this one's way + if (uri.has_value() && new_schema.is_boolean() && + new_vocabularies.contains( + sourcemeta::core::SchemaVocabularies::Known::OPENAPI_3_0_BASE)) + [[unlikely]] { + throw sourcemeta::blaze::CompilerError( + new_base, sourcemeta::core::to_pointer(target), + "This dialect does not support boolean schemas"); + } return compile_subschema( context, {.relative_pointer = new_relative_pointer, .schema = new_schema, - .vocabularies = entry.has_value() - ? context.frame.vocabularies(entry.value().get(), - context.resolver) - : schema_context.vocabularies, + .vocabularies = new_vocabularies, .base = new_base, .is_property_name = schema_context.is_property_name}, {.keyword = dynamic_context.keyword, diff --git a/vendor/blaze/src/compiler/default_compiler_draft3.h b/vendor/blaze/src/compiler/default_compiler_draft3.h index 2e9a2411a..d5726f5fd 100644 --- a/vendor/blaze/src/compiler/default_compiler_draft3.h +++ b/vendor/blaze/src/compiler/default_compiler_draft3.h @@ -117,72 +117,24 @@ static constexpr auto UNSUPPORTED_VALUE_FOR_DIALECT{ "The value this keyword is set to is not supported by this dialect"}; static constexpr auto PROHIBITED_KEYWORD_FOR_DIALECT{ "This keyword is prohibited by this dialect"}; -// A subschema that `narrows_type_away` drops is never compiled, so the refusal -// at the end of the dispatch table never reaches its members. Walk them here, -// as a member this dialect does not define is an error rather than one more -// keyword to pass by. The dialect is closed, so the applicators below are the -// complete set of places a further subschema can sit -static inline auto assert_members_are_permitted( - const sourcemeta::core::JSON &schema, - const sourcemeta::blaze::Context &context, - const sourcemeta::blaze::SchemaContext &schema_context, - const std::uint64_t depth = 0) -> void { - if (depth >= context.tweaks.max_depth) [[unlikely]] { - throw sourcemeta::blaze::CompilerDepthLimitError{context.tweaks.max_depth}; - } - - // The OpenAPI 3.0 Schema Object is the only dialect here that treats a - // member it does not define as an error, so it is the only one whose pruned - // subschemas have anything to answer for +// A subschema that `narrows_type_away` drops is never compiled, so neither +// the refusal at the end of the dispatch table nor the keyword shape checks +// ever reach its members. The OpenAPI 3.0 Schema Object is the only dialect +// here whose documents those checks judge as a whole, reachable or not, so +// compile the subschema the way a reachable one compiles and discard what it +// yields: the checks are the point rather than the instructions +static inline auto +compile_pruned_subschema(const sourcemeta::blaze::Context &context, + const sourcemeta::blaze::SchemaContext &schema_context, + const sourcemeta::core::WeakPointer &suffix) -> void { if (!schema_context.vocabularies.contains( sourcemeta::core::SchemaVocabularies::Known::OPENAPI_3_0_BASE)) { return; } - if (!schema.is_object()) { - return; - } - - // A Reference Object ignores whatever sits beside `$ref`, so those members - // answer to no keyword set - if (schema.defines("$ref")) { - return; - } - - for (const auto &entry : schema.as_object()) { - if (entry.first.starts_with("x-")) { - continue; - } - - if (context.walker(entry.first, schema_context.vocabularies).type == - sourcemeta::core::SchemaKeywordType::Unknown) { - throw sourcemeta::blaze::CompilerError( - schema_context.base, - absolute_schema_location(context, schema_context), - PROHIBITED_KEYWORD_FOR_DIALECT); - } - - if (entry.first == "not" || entry.first == "items" || - entry.first == "additionalProperties") { - assert_members_are_permitted(entry.second, context, schema_context, - depth + 1); - } else if (entry.first == "allOf" || entry.first == "anyOf" || - entry.first == "oneOf") { - if (entry.second.is_array()) { - for (const auto &element : entry.second.as_array()) { - assert_members_are_permitted(element, context, schema_context, - depth + 1); - } - } - } else if (entry.first == "properties") { - if (entry.second.is_object()) { - for (const auto &property : entry.second.as_object()) { - assert_members_are_permitted(property.second, context, schema_context, - depth + 1); - } - } - } - } + sourcemeta::blaze::compile(context, schema_context, + sourcemeta::blaze::relative_dynamic_context(), + suffix, suffix); } static constexpr auto EXPECTED_UNIQUE_VALUES{ @@ -845,7 +797,9 @@ auto compiler_draft3_applicator_properties_with_options( if (narrows_type_away(schema_context.schema, {"object"})) { for (const auto &entry : schema_context.schema.at(dynamic_context.keyword).as_object()) { - assert_members_are_permitted(entry.second, context, schema_context); + compile_pruned_subschema( + context, schema_context, + sourcemeta::blaze::make_weak_pointer(entry.first)); } return {}; @@ -1504,9 +1458,8 @@ auto compiler_draft3_applicator_additionalproperties_with_options( const DynamicContext &dynamic_context, const bool annotate, const bool track_evaluation) -> Instructions { if (narrows_type_away(schema_context.schema, {"object"})) { - assert_members_are_permitted( - schema_context.schema.at(dynamic_context.keyword), context, - schema_context); + compile_pruned_subschema(context, schema_context, + sourcemeta::core::EMPTY_WEAK_POINTER); return {}; } @@ -1859,9 +1812,8 @@ auto compiler_draft3_applicator_items_with_options( } if (narrows_type_away(schema_context.schema, {"array"})) { - assert_members_are_permitted( - schema_context.schema.at(dynamic_context.keyword), context, - schema_context); + compile_pruned_subschema(context, schema_context, + sourcemeta::core::EMPTY_WEAK_POINTER); return {}; } @@ -2471,33 +2423,6 @@ auto compiler_draft3_validation_minimum(const Context &context, schema_context.schema.at(dynamic_context.keyword)})}; } -// Whether the name was one this function knows, so that callers can tell an -// unrecognised name apart from one that set no bit -auto assign_type_bit(sourcemeta::blaze::ValueTypes &types, - const std::string_view name) -> bool { - if (name == "null") { - types.set(std::to_underlying(sourcemeta::core::JSON::Type::Null)); - } else if (name == "boolean") { - types.set(std::to_underlying(sourcemeta::core::JSON::Type::Boolean)); - } else if (name == "object") { - types.set(std::to_underlying(sourcemeta::core::JSON::Type::Object)); - } else if (name == "array") { - types.set(std::to_underlying(sourcemeta::core::JSON::Type::Array)); - } else if (name == "number") { - types.set(std::to_underlying(sourcemeta::core::JSON::Type::Integer)); - types.set(std::to_underlying(sourcemeta::core::JSON::Type::Real)); - types.set(std::to_underlying(sourcemeta::core::JSON::Type::Decimal)); - } else if (name == "integer") { - types.set(std::to_underlying(sourcemeta::core::JSON::Type::Integer)); - } else if (name == "string") { - types.set(std::to_underlying(sourcemeta::core::JSON::Type::String)); - } else { - return false; - } - - return true; -} - auto compiler_draft3_validation_type(const Context &context, const SchemaContext &schema_context, const DynamicContext &dynamic_context, @@ -2511,12 +2436,12 @@ auto compiler_draft3_validation_type(const Context &context, // This dialect types `type` as a string drawn from six names. It has no // array form and no null type, offering `nullable` in place of the latter. - // `assign_type_bit` answers for the seven JSON Schema names, so the null one - // has to be ruled out separately + // `draft3_set_type_bits` answers for the seven JSON Schema names, so the + // null one has to be ruled out separately if (schema_context.vocabularies.contains(Known::OPENAPI_3_0_BASE)) { ValueTypes recognised{}; if (!value.is_string() || value.to_string() == "null" || - !assign_type_bit(recognised, value.to_string())) { + !draft3_set_type_bits(value.to_string(), recognised)) { throw sourcemeta::blaze::CompilerError( schema_context.base, absolute_schema_location(context, schema_context), @@ -2910,7 +2835,7 @@ auto compiler_draft3_validation_type(const Context &context, continue; } - if (!assign_type_bit(types, element.to_string()) && !is_draft3) { + if (!draft3_set_type_bits(element.to_string(), types) && !is_draft3) { throw sourcemeta::blaze::CompilerError( schema_context.base, absolute_schema_location(context, schema_context), @@ -3240,6 +3165,35 @@ auto is_openapi_numeric_format(const SchemaContext &schema_context, name == "double"; } +// Every OpenAPI version types `int32`, `int64`, `float`, and `double` over +// numbers, so the assertion each name compiles to is the same wherever it +// appears. The caller answers for `name` being one of the four +auto make_openapi_numeric_format_assertion( + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context, + const sourcemeta::core::JSON::String &name) -> Instruction { + if (name == "int32") { + return make( + sourcemeta::blaze::InstructionIndex::AssertionNumberIntegerBounded, + context, schema_context, dynamic_context, + ValueIntegerBounds{std::numeric_limits::min(), + std::numeric_limits::max()}); + } + + if (name == "int64") { + return make( + sourcemeta::blaze::InstructionIndex::AssertionNumberIntegerBounded, + context, schema_context, dynamic_context, + ValueIntegerBounds{std::numeric_limits::min(), + std::numeric_limits::max()}); + } + + return make(sourcemeta::blaze::InstructionIndex::AssertionNumberType, context, + schema_context, dynamic_context, + name == "float" ? ValueNumberType::Float + : ValueNumberType::Double); +} + auto compiler_draft3_validation_format(const Context &context, const SchemaContext &schema_context, const DynamicContext &dynamic_context, @@ -3277,26 +3231,8 @@ auto compiler_draft3_validation_format(const Context &context, // TODO: Consider asserting the numeric and string formats that the // OpenAPI Format Registry defines if (is_openapi_numeric_format(schema_context, format)) { - Instructions instructions; - if (name == "int32") { - instructions.push_back(make( - sourcemeta::blaze::InstructionIndex::AssertionNumberIntegerBounded, - context, schema_context, dynamic_context, - ValueIntegerBounds{std::numeric_limits::min(), - std::numeric_limits::max()})); - } else if (name == "int64") { - instructions.push_back(make( - sourcemeta::blaze::InstructionIndex::AssertionNumberIntegerBounded, - context, schema_context, dynamic_context, - ValueIntegerBounds{std::numeric_limits::min(), - std::numeric_limits::max()})); - } else { - instructions.push_back( - make(sourcemeta::blaze::InstructionIndex::AssertionNumberType, - context, schema_context, dynamic_context, - name == "float" ? ValueNumberType::Float - : ValueNumberType::Double)); - } + Instructions instructions{make_openapi_numeric_format_assertion( + context, schema_context, dynamic_context, name)}; // Unlike the string formats, the annotation cannot be grouped by the // instance type, as `ControlGroupWhenType` does not take a number @@ -3424,24 +3360,12 @@ auto compiler_draft3_validation_format(const Context &context, schema_context.vocabularies.contains(Known::JSON_SCHEMA_DRAFT_7_HYPER)}; if (schema_context.vocabularies.contains(Known::OPENAPI_3_0_BASE)) { - // OpenAPI 3.0 defines these two for numbers, so they cannot resolve to a + // OpenAPI 3.0 defines these four for numbers, so they cannot resolve to a // string logical type like the rest of this chain does - if (name == "int32" || name == "int64") { - return {make( - sourcemeta::blaze::InstructionIndex::AssertionNumberIntegerBounded, - context, schema_context, dynamic_context, - name == "int32" - ? ValueIntegerBounds{std::numeric_limits::min(), - std::numeric_limits::max()} - : ValueIntegerBounds{std::numeric_limits::min(), - std::numeric_limits::max()})}; - } - - if (name == "float" || name == "double") { - return {make(sourcemeta::blaze::InstructionIndex::AssertionNumberType, - context, schema_context, dynamic_context, - name == "float" ? ValueNumberType::Float - : ValueNumberType::Double)}; + if (name == "int32" || name == "int64" || name == "float" || + name == "double") { + return {make_openapi_numeric_format_assertion(context, schema_context, + dynamic_context, name)}; } if (name == "date-time") { diff --git a/vendor/blaze/src/compiler/default_compiler_draft4.h b/vendor/blaze/src/compiler/default_compiler_draft4.h index 879169a12..1e8034e16 100644 --- a/vendor/blaze/src/compiler/default_compiler_draft4.h +++ b/vendor/blaze/src/compiler/default_compiler_draft4.h @@ -44,13 +44,14 @@ auto compiler_draft4_applicator_allof(const Context &context, const SchemaContext &schema_context, const DynamicContext &dynamic_context, const Instructions &) -> Instructions { - if (!is_schema_array( - schema_context.schema.at(dynamic_context.keyword), - booleans_are_schemas(schema_context.vocabularies), - in_place_applicators_may_be_empty(schema_context.vocabularies))) { + const auto allows_empty{ + in_place_applicators_may_be_empty(schema_context.vocabularies)}; + if (!is_schema_array(schema_context.schema.at(dynamic_context.keyword), + booleans_are_schemas(schema_context.vocabularies), + allows_empty)) { throw sourcemeta::blaze::CompilerError( schema_context.base, absolute_schema_location(context, schema_context), - EXPECTED_SCHEMA_ARRAY); + allows_empty ? EXPECTED_SCHEMA_ARRAY_ANY_SIZE : EXPECTED_SCHEMA_ARRAY); } Instructions children; @@ -94,13 +95,14 @@ auto compiler_draft4_applicator_anyof(const Context &context, const SchemaContext &schema_context, const DynamicContext &dynamic_context, const Instructions &) -> Instructions { - if (!is_schema_array( - schema_context.schema.at(dynamic_context.keyword), - booleans_are_schemas(schema_context.vocabularies), - in_place_applicators_may_be_empty(schema_context.vocabularies))) { + const auto allows_empty{ + in_place_applicators_may_be_empty(schema_context.vocabularies)}; + if (!is_schema_array(schema_context.schema.at(dynamic_context.keyword), + booleans_are_schemas(schema_context.vocabularies), + allows_empty)) { throw sourcemeta::blaze::CompilerError( schema_context.base, absolute_schema_location(context, schema_context), - EXPECTED_SCHEMA_ARRAY); + allows_empty ? EXPECTED_SCHEMA_ARRAY_ANY_SIZE : EXPECTED_SCHEMA_ARRAY); } // A disjunction over no branches can never be satisfied. Only a dialect that @@ -180,13 +182,14 @@ auto compiler_draft4_applicator_oneof(const Context &context, const SchemaContext &schema_context, const DynamicContext &dynamic_context, const Instructions &) -> Instructions { - if (!is_schema_array( - schema_context.schema.at(dynamic_context.keyword), - booleans_are_schemas(schema_context.vocabularies), - in_place_applicators_may_be_empty(schema_context.vocabularies))) { + const auto allows_empty{ + in_place_applicators_may_be_empty(schema_context.vocabularies)}; + if (!is_schema_array(schema_context.schema.at(dynamic_context.keyword), + booleans_are_schemas(schema_context.vocabularies), + allows_empty)) { throw sourcemeta::blaze::CompilerError( schema_context.base, absolute_schema_location(context, schema_context), - EXPECTED_SCHEMA_ARRAY); + allows_empty ? EXPECTED_SCHEMA_ARRAY_ANY_SIZE : EXPECTED_SCHEMA_ARRAY); } // A disjunction over no branches can never be satisfied. Only a dialect that diff --git a/vendor/core/src/core/crypto/crypto_hkdf_apple.cc b/vendor/core/src/core/crypto/crypto_hkdf_apple.cc index e1f168909..881011dbd 100644 --- a/vendor/core/src/core/crypto/crypto_hkdf_apple.cc +++ b/vendor/core/src/core/crypto/crypto_hkdf_apple.cc @@ -20,7 +20,11 @@ auto to_selector(const sourcemeta::core::KDFHash hash) noexcept -> int { return 2; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto octets(const std::string_view value) noexcept -> const unsigned char * { diff --git a/vendor/core/src/core/crypto/crypto_hkdf_openssl.cc b/vendor/core/src/core/crypto/crypto_hkdf_openssl.cc index 5a72bad77..65500459a 100644 --- a/vendor/core/src/core/crypto/crypto_hkdf_openssl.cc +++ b/vendor/core/src/core/crypto/crypto_hkdf_openssl.cc @@ -40,7 +40,11 @@ auto digest_name(const sourcemeta::core::KDFHash hash) noexcept -> const return "SHA512"; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } // An empty view may carry a null pointer, which the parameter interface would diff --git a/vendor/core/src/core/crypto/crypto_hkdf_windows.cc b/vendor/core/src/core/crypto/crypto_hkdf_windows.cc index 9d1f7a1fe..5778fe94b 100644 --- a/vendor/core/src/core/crypto/crypto_hkdf_windows.cc +++ b/vendor/core/src/core/crypto/crypto_hkdf_windows.cc @@ -26,7 +26,11 @@ auto hash_name(const sourcemeta::core::KDFHash hash) noexcept -> LPCWSTR { return BCRYPT_SHA512_ALGORITHM; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto hash_name_bytes(const sourcemeta::core::KDFHash hash) noexcept -> ULONG { @@ -39,7 +43,11 @@ auto hash_name_bytes(const sourcemeta::core::KDFHash hash) noexcept -> ULONG { return sizeof(BCRYPT_SHA512_ALGORITHM); } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto as_native(const std::string_view value) noexcept -> PUCHAR { diff --git a/vendor/core/src/core/crypto/crypto_rsa_oaep_apple.cc b/vendor/core/src/core/crypto/crypto_rsa_oaep_apple.cc index e708ab324..43db7f44a 100644 --- a/vendor/core/src/core/crypto/crypto_rsa_oaep_apple.cc +++ b/vendor/core/src/core/crypto/crypto_rsa_oaep_apple.cc @@ -29,7 +29,11 @@ auto to_oaep_algorithm(const RSAOAEPHash hash) -> SecKeyAlgorithm { return kSecKeyAlgorithmRSAEncryptionOAEPSHA256; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } } // namespace diff --git a/vendor/core/src/core/crypto/crypto_rsa_oaep_openssl.cc b/vendor/core/src/core/crypto/crypto_rsa_oaep_openssl.cc index 7f59cebd5..4648cc357 100644 --- a/vendor/core/src/core/crypto/crypto_rsa_oaep_openssl.cc +++ b/vendor/core/src/core/crypto/crypto_rsa_oaep_openssl.cc @@ -22,7 +22,11 @@ auto to_message_digest(const RSAOAEPHash hash) -> const EVP_MD * { return EVP_sha256(); } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto configure(EVP_PKEY_CTX *context, const RSAOAEPHash hash) -> bool { diff --git a/vendor/core/src/core/crypto/crypto_rsa_oaep_windows.cc b/vendor/core/src/core/crypto/crypto_rsa_oaep_windows.cc index 6b2632601..dd5ab0162 100644 --- a/vendor/core/src/core/crypto/crypto_rsa_oaep_windows.cc +++ b/vendor/core/src/core/crypto/crypto_rsa_oaep_windows.cc @@ -24,7 +24,11 @@ auto to_cng_algorithm(const RSAOAEPHash hash) -> LPCWSTR { return BCRYPT_SHA256_ALGORITHM; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto as_buffer(const std::string_view value) -> PUCHAR { diff --git a/vendor/core/src/core/crypto/crypto_sign_apple.cc b/vendor/core/src/core/crypto/crypto_sign_apple.cc index 1288584a9..6fdcfbbf7 100644 --- a/vendor/core/src/core/crypto/crypto_sign_apple.cc +++ b/vendor/core/src/core/crypto/crypto_sign_apple.cc @@ -34,7 +34,11 @@ auto to_sec_key_pkcs1_v15_algorithm( return kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA512; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } // These algorithm variants fix the salt length to the hash function output, @@ -51,7 +55,11 @@ auto to_sec_key_pss_algorithm( return kSecKeyAlgorithmRSASignatureMessagePSSSHA512; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto to_sec_key_ecdsa_algorithm( @@ -66,7 +74,11 @@ auto to_sec_key_ecdsa_algorithm( return kSecKeyAlgorithmECDSASignatureMessageX962SHA512; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto make_data(const std::string_view value) -> CFDataRef { @@ -332,7 +344,11 @@ auto make_private_key(const std::string_view pem) -> std::optional { } } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto make_ec_private_key(const EllipticCurve curve, @@ -482,7 +498,11 @@ auto eddsa_sign(const PrivateKey &key, const std::string_view message) return edwards448_sign(internal->edwards_seed, message); } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto derive_public_key(const PrivateKey &key) -> std::optional { @@ -542,7 +562,11 @@ auto derive_public_key(const PrivateKey &key) -> std::optional { } } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } } // namespace sourcemeta::core diff --git a/vendor/core/src/core/crypto/crypto_sign_openssl.cc b/vendor/core/src/core/crypto/crypto_sign_openssl.cc index 1912651bb..70b423020 100644 --- a/vendor/core/src/core/crypto/crypto_sign_openssl.cc +++ b/vendor/core/src/core/crypto/crypto_sign_openssl.cc @@ -35,7 +35,11 @@ auto to_message_digest( return EVP_sha512(); } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } // Refuse encrypted documents by offering no password, rather than letting the @@ -53,7 +57,11 @@ auto to_group_name(const sourcemeta::core::EllipticCurve curve) noexcept return "P-521"; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto to_pkey_id(const sourcemeta::core::EdwardsCurve curve) noexcept -> int { @@ -64,7 +72,11 @@ auto to_pkey_id(const sourcemeta::core::EdwardsCurve curve) noexcept -> int { return EVP_PKEY_ED448; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } // The signing functions only cover the three NIST prime curves, so a parsed key @@ -511,7 +523,11 @@ auto derive_public_key(const PrivateKey &key) -> std::optional { } } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } } // namespace sourcemeta::core diff --git a/vendor/core/src/core/crypto/crypto_sign_windows.cc b/vendor/core/src/core/crypto/crypto_sign_windows.cc index 70658f398..6b28915cb 100644 --- a/vendor/core/src/core/crypto/crypto_sign_windows.cc +++ b/vendor/core/src/core/crypto/crypto_sign_windows.cc @@ -40,7 +40,11 @@ auto to_cng_algorithm( return BCRYPT_SHA512_ALGORITHM; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto to_ecdsa_algorithm(const sourcemeta::core::EllipticCurve curve) noexcept @@ -54,7 +58,11 @@ auto to_ecdsa_algorithm(const sourcemeta::core::EllipticCurve curve) noexcept return BCRYPT_ECDSA_P521_ALGORITHM; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto to_ecc_private_magic(const sourcemeta::core::EllipticCurve curve) noexcept @@ -68,7 +76,11 @@ auto to_ecc_private_magic(const sourcemeta::core::EllipticCurve curve) noexcept return BCRYPT_ECDSA_PRIVATE_P521_MAGIC; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } struct KeyPair { @@ -414,7 +426,11 @@ auto make_private_key(const std::string_view pem) -> std::optional { } } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto make_ec_private_key(const EllipticCurve curve, @@ -548,7 +564,11 @@ auto eddsa_sign(const PrivateKey &key, const std::string_view message) return edwards448_sign(internal->edwards_seed, message); } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto derive_public_key(const PrivateKey &key) -> std::optional { @@ -607,7 +627,11 @@ auto derive_public_key(const PrivateKey &key) -> std::optional { } } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } } // namespace sourcemeta::core diff --git a/vendor/core/src/core/crypto/crypto_verify_apple.cc b/vendor/core/src/core/crypto/crypto_verify_apple.cc index 44d71be8d..16777bf47 100644 --- a/vendor/core/src/core/crypto/crypto_verify_apple.cc +++ b/vendor/core/src/core/crypto/crypto_verify_apple.cc @@ -33,7 +33,11 @@ auto to_sec_key_pkcs1_v15_algorithm( return kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA512; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } // These algorithm variants fix the salt length to the hash function output, @@ -50,7 +54,11 @@ auto to_sec_key_pss_algorithm( return kSecKeyAlgorithmRSASignatureMessagePSSSHA512; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto to_sec_key_ecdsa_algorithm( @@ -65,7 +73,11 @@ auto to_sec_key_ecdsa_algorithm( return kSecKeyAlgorithmECDSASignatureMessageX962SHA512; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto make_data(const std::string_view value) -> CFDataRef { @@ -355,7 +367,11 @@ auto eddsa_verify(const PublicKey &key, const std::string_view message, return edwards448_verify(internal->edwards_point, message, signature); } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto rsa_public_components(const PublicKey &key) diff --git a/vendor/core/src/core/crypto/crypto_verify_openssl.cc b/vendor/core/src/core/crypto/crypto_verify_openssl.cc index bd71e9196..d3b84cc7f 100644 --- a/vendor/core/src/core/crypto/crypto_verify_openssl.cc +++ b/vendor/core/src/core/crypto/crypto_verify_openssl.cc @@ -33,7 +33,11 @@ auto to_message_digest( return EVP_sha512(); } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto to_group_name(const sourcemeta::core::EllipticCurve curve) noexcept @@ -47,7 +51,11 @@ auto to_group_name(const sourcemeta::core::EllipticCurve curve) noexcept return "P-521"; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto to_pkey_id(const sourcemeta::core::EdwardsCurve curve) noexcept -> int { @@ -58,7 +66,11 @@ auto to_pkey_id(const sourcemeta::core::EdwardsCurve curve) noexcept -> int { return EVP_PKEY_ED448; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto native_rsa_key(const std::string_view modulus, diff --git a/vendor/core/src/core/crypto/crypto_verify_windows.cc b/vendor/core/src/core/crypto/crypto_verify_windows.cc index 7fe080434..f09a7b2b0 100644 --- a/vendor/core/src/core/crypto/crypto_verify_windows.cc +++ b/vendor/core/src/core/crypto/crypto_verify_windows.cc @@ -38,7 +38,11 @@ auto to_cng_algorithm( return BCRYPT_SHA512_ALGORITHM; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto to_ecdsa_algorithm(const sourcemeta::core::EllipticCurve curve) noexcept @@ -52,7 +56,11 @@ auto to_ecdsa_algorithm(const sourcemeta::core::EllipticCurve curve) noexcept return BCRYPT_ECDSA_P521_ALGORITHM; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto to_ecc_public_magic(const sourcemeta::core::EllipticCurve curve) noexcept @@ -66,7 +74,11 @@ auto to_ecc_public_magic(const sourcemeta::core::EllipticCurve curve) noexcept return BCRYPT_ECDSA_PUBLIC_P521_MAGIC; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } struct KeyPair { @@ -355,7 +367,11 @@ auto eddsa_verify(const PublicKey &key, const std::string_view message, return edwards448_verify(internal->edwards_point, message, signature); } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto rsa_public_components(const PublicKey &key) diff --git a/vendor/core/src/core/diff/diff.cc b/vendor/core/src/core/diff/diff.cc index 081bd669b..756ba6429 100644 --- a/vendor/core/src/core/diff/diff.cc +++ b/vendor/core/src/core/diff/diff.cc @@ -69,6 +69,31 @@ auto to_identities( } } +// The search is given its workspace here rather than alongside the result, so +// that the two buffers it sizes to the span of the change are given up before +// anything is made of what the search found +auto compare_with_myers(const std::vector &original_identities, + const std::vector &modified_identities, + const std::size_t prefix, + const std::size_t original_end, + const std::size_t modified_end, + std::vector &original_changed, + std::vector &modified_changed) -> void { + sourcemeta::core::internal::MyersWorkspace workspace; + // A search only needs its workspace once both sides have something left, as + // any other case resolves to a plain insertion or deletion + if (original_end > prefix && modified_end > prefix) { + const auto span{(original_end - prefix) + (modified_end - prefix)}; + workspace.forward.assign((2 * span) + 3, 0); + workspace.backward.assign((2 * span) + 3, 0); + workspace.offset = static_cast(span + 1); + } + + sourcemeta::core::internal::myers_compare( + original_identities, prefix, original_end, modified_identities, prefix, + modified_end, original_changed, modified_changed, workspace); +} + // Slide every run of changed lines as far towards the end of the input as the // surrounding lines allow, which is what makes paired changes line up auto compact_changes(const std::vector &lines, @@ -225,22 +250,11 @@ auto diff(const std::string_view original, const std::string_view modified, std::vector modified_changed(modified_size, false); switch (algorithm) { - case Diff::Algorithm::Myers: { - internal::MyersWorkspace workspace; - // A search only needs its workspace once both sides have something left, - // as any other case resolves to a plain insertion or deletion - if (original_end > prefix && modified_end > prefix) { - const auto span{(original_end - prefix) + (modified_end - prefix)}; - workspace.forward.assign((2 * span) + 3, 0); - workspace.backward.assign((2 * span) + 3, 0); - workspace.offset = static_cast(span + 1); - } - - internal::myers_compare(original_identities, prefix, original_end, - modified_identities, prefix, modified_end, - original_changed, modified_changed, workspace); + case Diff::Algorithm::Myers: + compare_with_myers(original_identities, modified_identities, prefix, + original_end, modified_end, original_changed, + modified_changed); break; - } } compact_changes(result.original, result.original_ends_with_newline, diff --git a/vendor/core/src/core/diff/myers.h b/vendor/core/src/core/diff/myers.h index 5881f1adb..c1ba7f363 100644 --- a/vendor/core/src/core/diff/myers.h +++ b/vendor/core/src/core/diff/myers.h @@ -3,7 +3,6 @@ #include // assert #include // std::size_t, std::ptrdiff_t -#include // std::unreachable #include // std::vector namespace sourcemeta::core::internal { @@ -46,8 +45,13 @@ inline auto myers_middle_snake(const std::vector &original, workspace.forward[static_cast(offset + 1)] = 0; workspace.backward[static_cast(offset + 1)] = 0; - const auto limit{(original_size + modified_size + 1) / 2}; - for (std::ptrdiff_t depth{0}; depth <= limit; ++depth) { + [[maybe_unused]] const auto limit{(original_size + modified_size + 1) / 2}; + // A middle snake always lands within the bounds the search was given, so one + // of the returns below is always taken. Spelling the search as a loop with no + // exit of its own is what says as much to every compiler, which otherwise has + // to be told separately that the end of the function is never reached + for (std::ptrdiff_t depth{0};; ++depth) { + assert(depth <= limit); for (std::ptrdiff_t diagonal{-depth}; diagonal <= depth; diagonal += 2) { const auto lower{ workspace.forward[static_cast(offset + diagonal - 1)]}; @@ -121,13 +125,6 @@ inline auto myers_middle_snake(const std::vector &original, } } } - - // A middle snake always lands within the bounds the search was given, so the - // loop above returns rather than running out. Unlike a function that ends - // after an exhaustive switch, the search is a loop whose returns are all - // conditional, so every compiler has to be told the end is never reached - assert(false); - std::unreachable(); } inline auto myers_compare(const std::vector &original, @@ -137,6 +134,11 @@ inline auto myers_compare(const std::vector &original, std::vector &original_changed, std::vector &modified_changed, MyersWorkspace &workspace) -> void { + // The caller takes off the lines the two sides share at the head and at the + // tail before the search begins, but a middle snake can still leave a + // sub-problem whose own ends match: a forward search never looks behind + // where its snake starts, and a backward search never looks past where its + // snake ends, so each recursion trims again for itself while (original_start < original_end && modified_start < modified_end && original[original_start] == modified[modified_start]) { original_start += 1; diff --git a/vendor/core/src/core/dns/idn_hostname.cc b/vendor/core/src/core/dns/idn_hostname.cc index 2dea961ca..672bbad51 100644 --- a/vendor/core/src/core/dns/idn_hostname.cc +++ b/vendor/core/src/core/dns/idn_hostname.cc @@ -61,12 +61,11 @@ auto validate_idn_labels(const std::u32string_view codepoints) -> bool { // the corresponding A-label. std::size_t a_label_octets{label.size()}; if (*kind == IDNALabelKind::ULabel) { - try { - const auto body{utf32_to_punycode(decoded)}; - a_label_octets = 4 + body.size(); - } catch (const PunycodeError &) { - return false; - } + // Classifying the label held it to the octet count a label may carry, + // which leaves it far shorter than what the position counters of the + // encoding could ever run past, so the encoding always answers + const auto body{utf32_to_punycode(decoded)}; + a_label_octets = 4 + body.size(); } else if (*kind == IDNALabelKind::Ascii) { // RFC 5891 §4.2.3.1: a label must not contain "--" in the third and // fourth positions unless it is a valid A-label (an "xn--" ACE label, diff --git a/vendor/core/src/core/gzip/inflate.h b/vendor/core/src/core/gzip/inflate.h index 7f4aa589a..9951d3032 100644 --- a/vendor/core/src/core/gzip/inflate.h +++ b/vendor/core/src/core/gzip/inflate.h @@ -664,10 +664,7 @@ class InflateDecoder { break; case State::StoredLength: - if (!this->read_stored_length(buffers)) { - return this->leave(buffers, InflateStatus::NeedInput); - } - + this->read_stored_length(buffers); break; case State::StoredData: { const auto progress{this->copy_stored_data(buffers)}; @@ -1100,13 +1097,12 @@ class InflateDecoder { } } - auto read_stored_length(InflateBuffers &buffers) -> bool { + // A block header is only read once the whole margin is in hand, and reading + // it gives back more input than it takes, so these four bytes always stand + // behind it unless the source ended in the middle of them + auto read_stored_length(InflateBuffers &buffers) -> void { if (available_input(buffers) < 4) { - if (buffers.input_final) { - unexpected_end(); - } - - return false; + unexpected_end(); } const auto length{static_cast(buffers.input_next[0]) | @@ -1121,7 +1117,6 @@ class InflateDecoder { buffers.input_next += 4; this->stored_remaining_ = length; this->state_ = State::StoredData; - return true; } auto copy_stored_data(InflateBuffers &buffers) -> InflateStatus { diff --git a/vendor/core/src/core/http/from_date.cc b/vendor/core/src/core/http/from_date.cc index c2ff17f10..af74a0dca 100644 --- a/vendor/core/src/core/http/from_date.cc +++ b/vendor/core/src/core/http/from_date.cc @@ -7,7 +7,7 @@ namespace sourcemeta::core { -auto http_from_date(const std::string_view value) noexcept +auto http_from_date(const std::string_view value) -> std::optional { if (const auto result{from_imf_fixdate(value)}; result.has_value()) { return result; diff --git a/vendor/core/src/core/http/include/sourcemeta/core/http.h b/vendor/core/src/core/http/include/sourcemeta/core/http.h index 215572230..81f410059 100644 --- a/vendor/core/src/core/http/include/sourcemeta/core/http.h +++ b/vendor/core/src/core/http/include/sourcemeta/core/http.h @@ -234,7 +234,7 @@ auto http_negotiate_encoding( /// "Sun Nov 6 08:49:37 1994").has_value()); /// ``` SOURCEMETA_CORE_HTTP_EXPORT -auto http_from_date(const std::string_view value) noexcept +auto http_from_date(const std::string_view value) -> std::optional; /// @ingroup http diff --git a/vendor/core/src/core/http/include/sourcemeta/core/http_message.h b/vendor/core/src/core/http/include/sourcemeta/core/http_message.h index 4168e3bae..de641e327 100644 --- a/vendor/core/src/core/http/include/sourcemeta/core/http_message.h +++ b/vendor/core/src/core/http/include/sourcemeta/core/http_message.h @@ -9,6 +9,7 @@ #include // std::nullopt, std::optional #include // std::string #include // std::string_view +#include // std::is_same_v #include // std::move namespace sourcemeta::core { @@ -397,26 +398,29 @@ inline auto http_serialize_headers(const Headers &headers) -> std::string { continue; } - // RFC 9112 §5.1 notes that "a single SP preceding the field line - // value is preferred for consistent readability by humans" + // A field value either carries its own bytes or already is the bytes, so + // which of the two it is settles only what gets read out of it here. A + // value that carries them hands back a view of storage it keeps, which is + // what lets the view below outlive the call that produced it + std::string_view bytes; if constexpr (requires { value.bytes(); }) { - if (http_field_line_has_forbidden_byte(value.bytes())) { - continue; - } - - result += name; - result += ": "; - result += value.bytes(); + static_assert(std::is_same_v, + "A field value must hand back a view of bytes it keeps, " + "as an owning result would leave nothing to write out"); + bytes = value.bytes(); } else { - if (http_field_line_has_forbidden_byte(value)) { - continue; - } + bytes = value; + } - result += name; - result += ": "; - result += value; + if (http_field_line_has_forbidden_byte(bytes)) { + continue; } + // RFC 9112 §5.1 notes that "a single SP preceding the field line + // value is preferred for consistent readability by humans" + result += name; + result += ": "; + result += bytes; result += "\r\n"; } diff --git a/vendor/core/src/core/idna/idna.cc b/vendor/core/src/core/idna/idna.cc index 3abb2d051..304a4ecfe 100644 --- a/vendor/core/src/core/idna/idna.cc +++ b/vendor/core/src/core/idna/idna.cc @@ -5,6 +5,7 @@ #include #include // std::ranges::lower_bound +#include // assert #include // std::size_t #include // std::optional, std::nullopt #include // std::string, std::u32string @@ -67,11 +68,10 @@ auto validate_a_label_body(const std::string_view encoded, // RFC 5891 §4.2.1: "verify that the A-label produced by the step in // Section 4.4 matches the one provided as input", so re-encoding the decoded // U-label must yield the lowercased bytes we decoded from - try { - return utf32_to_punycode(decoded) == body; - } catch (const PunycodeError &) { - return false; - } + // The A-label this decoded came from is held to the octet count a label may + // carry, which leaves what is re-encoded far shorter than what the position + // counters of the encoding could run past, so the encoding always answers + return utf32_to_punycode(decoded) == body; } } // namespace @@ -408,10 +408,15 @@ auto idna_passes_bidi_rule(const std::u32string_view label) noexcept -> bool { } // RFC 5893 §2 conditions 3 and 6: the label must end with a specific - // class, optionally followed by NSM characters. - for (std::size_t index = label.size(); index-- > 0;) { + // class, optionally followed by NSM characters. The first character was held + // to L, R, or AL above and none of those is an NSM, so walking back from the + // end always reaches a character that answers, which is why the walk is + // spelled without an exit of its own + for (std::size_t index{label.size()};;) { + index -= 1; const auto class_value{bidi_class(label[index])}; if (class_value == BidiClass::NonspacingMark) { + assert(index > 0); continue; } if (is_rtl_label) { @@ -423,8 +428,6 @@ auto idna_passes_bidi_rule(const std::u32string_view label) noexcept -> bool { return class_value == BidiClass::LeftToRight || class_value == BidiClass::EuropeanNumber; } - - return false; } auto idna_is_valid_a_label(const std::string_view label) -> bool { diff --git a/vendor/core/src/core/jsonld/jsonld.cc b/vendor/core/src/core/jsonld/jsonld.cc index 41af0305c..df4ef5f9f 100644 --- a/vendor/core/src/core/jsonld/jsonld.cc +++ b/vendor/core/src/core/jsonld/jsonld.cc @@ -25,10 +25,13 @@ auto run_expansion(ExpansionState &state, ActiveContext &active_context, } if (expanded.is_object()) { - if (expanded.empty() || (expanded.object_size() == 1 && - expanded.defines(KEYWORD_ID, KEYWORD_ID_HASH))) { - return JSON::make_array(); - } + // A map that names nothing but which node it is, or nothing at all, is + // already dropped where free-floating values are, and the only member + // that stands in for the whole document carries an array, so whatever + // arrives here as a map has something left to say + assert(!expanded.empty() && + !(expanded.object_size() == 1 && + expanded.defines(KEYWORD_ID, KEYWORD_ID_HASH))); auto result{JSON::make_array()}; result.push_back(std::move(expanded)); return result; diff --git a/vendor/core/src/core/jsonld/jsonld_compaction.cc b/vendor/core/src/core/jsonld/jsonld_compaction.cc index 327b7380c..6fd96dcaf 100644 --- a/vendor/core/src/core/jsonld/jsonld_compaction.cc +++ b/vendor/core/src/core/jsonld/jsonld_compaction.cc @@ -54,20 +54,6 @@ auto add_value(JSON &result, const JSON::String &key, JSON &&value, existing.push_back(std::move(value)); } -// A value object carrying a JSON literal whose value is null. -auto is_json_literal_null(const JSON &element) -> bool { - // Whatever stands as the value of a property in an expanded document is an - // object, which is what the one place this is asked from hands over - assert(element.is_object()); - const auto *const contents{element.try_at(KEYWORD_VALUE, KEYWORD_VALUE_HASH)}; - if (contents == nullptr || !contents->is_null()) { - return false; - } - const auto *const type{element.try_at(KEYWORD_TYPE, KEYWORD_TYPE_HASH)}; - return type != nullptr && type->is_string() && - type->to_string() == KEYWORD_JSON; -} - // The object a property is written into: the result itself, or a nesting // container when the term carries an @nest mapping. auto nest_target(JSON &result, const TermDefinition *const definition, @@ -109,25 +95,22 @@ auto compact(ExpansionState &state, const ActiveContext &active_context, throw JSONLDError("Maximum nesting depth exceeded", EMPTY_WEAK_POINTER); } - if (!element.is_object() && !element.is_array()) { - return element; - } + // Compaction walks an expanded document, where a scalar only ever stands as + // what a value object holds, which never reaches here on its own + assert(element.is_object() || element.is_array()); const auto *definition{definition_for(active_context, active_property)}; if (element.is_array()) { auto result{JSON::make_array()}; for (const auto &item : element.as_array()) { - auto compacted{compact(state, active_context, inverse_context, - active_property, item, compact_arrays)}; - // A JSON literal holding null compacts to a bare null under a term - // coerced to @json, and that null is data rather than absence, so it - // survives even though the algorithm otherwise drops null items - // (JSON-LD 1.1 API Section 6.1.2: "If compacted item is not null, then - // append it to result"). Dropping it would silently lose the literal. - if (!compacted.is_null() || is_json_literal_null(item)) { - result.push_back(std::move(compacted)); - } + // The step that drops a null item (JSON-LD 1.1 API Section 6.1.2: "If + // compacted item is not null, then append it to result") has nothing to + // act on here. The only null an expanded item compacts to is the one a + // JSON literal holds, which is data rather than absence, and dropping it + // would silently lose the literal + result.push_back(compact(state, active_context, inverse_context, + active_property, item, compact_arrays)); } const bool force_array{!compact_arrays || (active_property.has_value() && diff --git a/vendor/core/src/core/jsonld/jsonld_context_processing.cc b/vendor/core/src/core/jsonld/jsonld_context_processing.cc index e8a6e09ab..02d394f3e 100644 --- a/vendor/core/src/core/jsonld/jsonld_context_processing.cc +++ b/vendor/core/src/core/jsonld/jsonld_context_processing.cc @@ -4,6 +4,7 @@ #include #include +#include // assert #include // std::make_shared #include // std::optional #include // std::move, std::pair @@ -100,9 +101,9 @@ auto is_version_1_1(const JSON &version) -> bool { auto is_input_authored(const JSONLDError &error, const JSON &context, const WeakPointer &location) -> bool { const auto &pointer{error.pointer()}; - if (pointer.size() <= location.size()) { - return true; - } + // Everything the merged context is held to account for is one of its + // entries, so what reports against it reaches past the context itself + assert(pointer.size() > location.size()); const auto &token{pointer.at(location.size())}; return token.is_property() && context.defines(token.to_property()); } diff --git a/vendor/core/src/core/jsonld/jsonld_expansion.cc b/vendor/core/src/core/jsonld/jsonld_expansion.cc index 119fb5604..8e1a8d4e6 100644 --- a/vendor/core/src/core/jsonld/jsonld_expansion.cc +++ b/vendor/core/src/core/jsonld/jsonld_expansion.cc @@ -175,6 +175,23 @@ auto container_includes(const TermDefinition *const definition, return false; } +// Whether the items being expanded become the items of a list, which is +// either the list they are written in or the one the property they stand +// under collects them into +auto collects_into_a_list(const ActiveContext &active_context, + const std::optional &active_property, + const JSON::StringView name) -> bool { + if (name == KEYWORD_LIST) { + return true; + } + + const auto term{active_property.has_value() + ? active_context.terms.find(active_property.value()) + : active_context.terms.cend()}; + return term != active_context.terms.cend() && + container_includes(&term->second, KEYWORD_LIST); +} + // Expand a single @type value against the context that preceded type-scoped // processing. auto expand_type(ExpansionState &state, const ActiveContext &type_context, @@ -693,7 +710,11 @@ auto expand_entries(ExpansionState &state, ActiveContext &active_context, } value_index += 1; } - if (name == KEYWORD_LIST && state.processing_1_0) { + // JSON-LD 1.0 refuses a list among the items of a list, whichever + // keyword hands those items over (JSON-LD 1.0 API Expansion Algorithm + // step 3.2) + if (state.processing_1_0 && + collects_into_a_list(active_context, active_property, name)) { for (const auto &item : elements.as_array()) { if (is_list_object(item)) { throw JSONLDError("List of lists", @@ -1200,22 +1221,12 @@ auto expand_entries(ExpansionState &state, ActiveContext &active_context, } // A @list container wraps the expanded value, including a @json-coerced - // one. + // one. A list among the items of the list this makes is refused by + // JSON-LD 1.0 where the array form and the keyword form gather those + // items, and welcomed by 1.1, so neither leaves anything to settle here if (container_includes(definition, KEYWORD_LIST) && - !expanded_value.is_null() && - !(expanded_value.is_object() && - expanded_value.defines(KEYWORD_LIST, KEYWORD_LIST_HASH))) { + !expanded_value.is_null() && !is_list_object(expanded_value)) { expanded_value = into_array(std::move(expanded_value)); - if (state.processing_1_0) { - for (const auto &item : expanded_value.as_array()) { - if (is_list_object(item)) { - throw JSONLDError("List of lists", - forbidden_member_pointer( - state, active_context, property, entry.second, - entry_pointer, is_list_object)); - } - } - } auto wrapper{JSON::make_object()}; wrapper.assign_assume_new(JSON::String{KEYWORD_LIST}, std::move(expanded_value), KEYWORD_LIST_HASH); diff --git a/vendor/core/src/core/jsonld/jsonld_iri_compaction.cc b/vendor/core/src/core/jsonld/jsonld_iri_compaction.cc index 447468d37..4b6192fbd 100644 --- a/vendor/core/src/core/jsonld/jsonld_iri_compaction.cc +++ b/vendor/core/src/core/jsonld/jsonld_iri_compaction.cc @@ -5,6 +5,7 @@ #include "jsonld_algorithms.h" #include "jsonld_keywords.h" +#include // assert #include // std::optional, std::nullopt #include // std::vector @@ -210,9 +211,9 @@ auto compact_iri(const ActiveContext &active_context, common_type = JSON::String{KEYWORD_NONE}; } } - if (!common_language.has_value()) { - common_language = JSON::String{KEYWORD_NONE}; - } + // An empty list takes the default language, and any other settles one + // from its first item, so the language is spoken for either way + assert(common_language.has_value()); if (!common_type.has_value()) { common_type = JSON::String{KEYWORD_NONE}; } diff --git a/vendor/core/src/core/jsonld/jsonld_node_map.cc b/vendor/core/src/core/jsonld/jsonld_node_map.cc index 69e545ff0..43ff0bd3d 100644 --- a/vendor/core/src/core/jsonld/jsonld_node_map.cc +++ b/vendor/core/src/core/jsonld/jsonld_node_map.cc @@ -5,6 +5,7 @@ #include "jsonld_keywords.h" #include // std::ranges::sort +#include // assert #include // std::optional, std::nullopt #include // std::to_string #include // std::move @@ -14,12 +15,11 @@ namespace sourcemeta::core { namespace { -// Append a value to the property array of node, creating the array as needed. +// Append a value to the property array of node, which the caller makes before +// it descends into the values that land there auto append_value(JSON &node, const JSON::StringView property, JSON value) -> void { - if (!node.defines(property)) { - node.assign_assume_new(JSON::String{property}, JSON::make_array()); - } + assert(node.defines(property)); node.at(property).push_back(std::move(value)); } @@ -80,7 +80,9 @@ auto generate_node_map(BlankNodeState &state, JSON &node_map, // The algorithm consumes entries of element, so work on a mutable copy. JSON working{element}; - // Relabel blank node identifiers used as @type values. + // Relabel blank node identifiers used as @type values. A node object states + // its types as an array, and the datatype a value object states is an IRI, + // so a name to relabel only ever stands among the items of an array if (working.defines(KEYWORD_TYPE, KEYWORD_TYPE_HASH)) { auto &type_value{working.at(KEYWORD_TYPE, KEYWORD_TYPE_HASH)}; if (type_value.is_array()) { @@ -89,10 +91,6 @@ auto generate_node_map(BlankNodeState &state, JSON &node_map, item = JSON{generate_blank_node_identifier(state, item.to_string())}; } } - } else if (type_value.is_string() && - is_blank_node(type_value.to_string())) { - type_value = - JSON{generate_blank_node_identifier(state, type_value.to_string())}; } } diff --git a/vendor/core/src/core/jsonld/jsonld_serialise.h b/vendor/core/src/core/jsonld/jsonld_serialise.h index ce794e741..ae6e86914 100644 --- a/vendor/core/src/core/jsonld/jsonld_serialise.h +++ b/vendor/core/src/core/jsonld/jsonld_serialise.h @@ -231,10 +231,10 @@ inline auto typed_literal_lexical_form(const JSON &value, } return fixed_lexical_form(decimal); } - case JSON::Type::Null: case JSON::Type::String: case JSON::Type::Array: case JSON::Type::Object: + case JSON::Type::Null: return std::nullopt; } diff --git a/vendor/core/src/core/jsonpath/jsonpath.cc b/vendor/core/src/core/jsonpath/jsonpath.cc index 9bab19fa3..b6c762d7d 100644 --- a/vendor/core/src/core/jsonpath/jsonpath.cc +++ b/vendor/core/src/core/jsonpath/jsonpath.cc @@ -307,9 +307,9 @@ auto filter_query_visit_iterative( const auto *const selectors_end{selector + segment.selectors.size()}; for (; selector != selectors_end; ++selector) { switch (static_cast(selector->index())) { - case JSONPath::SelectorKind::Name: { - const auto *entry{std::get_if(selector)}; + case JSONPath::SelectorKind::Name: if (type == JSON::Type::Object) { + const auto *entry{std::get_if(selector)}; const auto *child{current.try_at(entry->name, entry->hash)}; if (child != nullptr) { pool.push_back({.node = child, .cursor = item.cursor + 1}); @@ -317,7 +317,6 @@ auto filter_query_visit_iterative( } break; - } case JSONPath::SelectorKind::Wildcard: if (type == JSON::Type::Object) { const auto &object{current.as_object()}; @@ -335,9 +334,9 @@ auto filter_query_visit_iterative( } break; - case JSONPath::SelectorKind::Index: { - const auto *entry{std::get_if(selector)}; + case JSONPath::SelectorKind::Index: if (type == JSON::Type::Array) { + const auto *entry{std::get_if(selector)}; const auto &array{current.as_array()}; const auto size{static_cast(array.size())}; const auto index{entry->index < 0 ? entry->index + size @@ -350,7 +349,6 @@ auto filter_query_visit_iterative( } break; - } case JSONPath::SelectorKind::Slice: { const auto *entry{std::get_if(selector)}; if (type == JSON::Type::Array) { @@ -863,6 +861,27 @@ inline auto filter_compare(const JSONPath::FilterComparison &comparison, #endif } +// A test either runs a query and answers whether it reached anything or calls +// a function that answers on its own, and what it comes to may be negated +// either way +inline auto filter_test_matches(const JSONPath::FilterTest &test, + const JSON &candidate, const JSON &root) + -> bool { + bool result{false}; + if (test.subject.index() == 0) { + const auto &query{*std::get_if(&test.subject)}; + result = !filter_query_visit(query.segments, 0, + query.relative ? candidate : root, root, + [](const JSON &) -> bool { return false; }); + } else { + result = evaluate_logical_function( + *std::get_if(&test.subject), candidate, + root); + } + + return test.negated ? !result : result; +} + inline auto filter_matches(const JSONPath::FilterExpression &expression, const JSON &candidate, const JSON &root) -> bool { switch ( @@ -871,22 +890,10 @@ inline auto filter_matches(const JSONPath::FilterExpression &expression, return filter_compare( *std::get_if(&expression.value), candidate, root); - case JSONPath::FilterExpressionKind::Test: { - const auto &test{*std::get_if(&expression.value)}; - bool result{false}; - if (test.subject.index() == 0) { - const auto &query{*std::get_if(&test.subject)}; - result = !filter_query_visit( - query.segments, 0, query.relative ? candidate : root, root, - [](const JSON &) -> bool { return false; }); - } else { - result = evaluate_logical_function( - *std::get_if(&test.subject), - candidate, root); - } - - return test.negated ? !result : result; - } + case JSONPath::FilterExpressionKind::Test: + return filter_test_matches( + *std::get_if(&expression.value), candidate, + root); case JSONPath::FilterExpressionKind::Conjunction: { const auto &conjunction{ *std::get_if(&expression.value)}; @@ -1005,9 +1012,9 @@ inline auto evaluate_query(const std::vector &segments, const auto *const selectors_end{selector + segment.selectors.size()}; for (; selector != selectors_end; ++selector) { switch (static_cast(selector->index())) { - case JSONPath::SelectorKind::Name: { - const auto *entry{std::get_if(selector)}; + case JSONPath::SelectorKind::Name: if (type == JSON::Type::Object) { + const auto *entry{std::get_if(selector)}; const auto *child{current.try_at(entry->name, entry->hash)}; if (child != nullptr) { stack.push_visit_property(child, item.cursor + 1, child_depth, @@ -1016,7 +1023,6 @@ inline auto evaluate_query(const std::vector &segments, } break; - } case JSONPath::SelectorKind::Wildcard: if (type == JSON::Type::Object) { const auto &object{current.as_object()}; @@ -1037,9 +1043,9 @@ inline auto evaluate_query(const std::vector &segments, } break; - case JSONPath::SelectorKind::Index: { - const auto *entry{std::get_if(selector)}; + case JSONPath::SelectorKind::Index: if (type == JSON::Type::Array) { + const auto *entry{std::get_if(selector)}; const auto &array{current.as_array()}; const auto size{static_cast(array.size())}; const auto index{entry->index < 0 ? entry->index + size @@ -1053,7 +1059,6 @@ inline auto evaluate_query(const std::vector &segments, } break; - } case JSONPath::SelectorKind::Slice: { const auto *entry{std::get_if(selector)}; if (type == JSON::Type::Array) { @@ -1190,9 +1195,9 @@ inline auto evaluate_selectors(const std::vector &segments, const auto *const selectors_end{selector + segment.selectors.size()}; for (; selector != selectors_end; ++selector) { switch (static_cast(selector->index())) { - case JSONPath::SelectorKind::Name: { - const auto *entry{std::get_if(selector)}; + case JSONPath::SelectorKind::Name: if (type == JSON::Type::Object) { + const auto *entry{std::get_if(selector)}; const auto *child{current.try_at(entry->name, entry->hash)}; if (child != nullptr) { state.frames.push_property(entry->name, entry->hash); @@ -1202,7 +1207,6 @@ inline auto evaluate_selectors(const std::vector &segments, } break; - } case JSONPath::SelectorKind::Wildcard: if (type == JSON::Type::Object) { const auto &object{current.as_object()}; @@ -1225,9 +1229,9 @@ inline auto evaluate_selectors(const std::vector &segments, } break; - case JSONPath::SelectorKind::Index: { - const auto *entry{std::get_if(selector)}; + case JSONPath::SelectorKind::Index: if (type == JSON::Type::Array) { + const auto *entry{std::get_if(selector)}; const auto &array{current.as_array()}; const auto size{static_cast(array.size())}; const auto index{entry->index < 0 ? entry->index + size @@ -1243,7 +1247,6 @@ inline auto evaluate_selectors(const std::vector &segments, } break; - } case JSONPath::SelectorKind::Slice: { const auto *entry{std::get_if(selector)}; if (type == JSON::Type::Array) { diff --git a/vendor/core/src/core/jsonpath/parser.h b/vendor/core/src/core/jsonpath/parser.h index 1cd5e7aec..d3b5ff001 100644 --- a/vendor/core/src/core/jsonpath/parser.h +++ b/vendor/core/src/core/jsonpath/parser.h @@ -886,6 +886,9 @@ class JSONPathParser { return JSON{exact.value()}; } + // The range check above is on the value, which a literal of zero passes + // however it spells its exponent, so what is read here can still name a + // scale no decimal carries try { return JSON{Decimal{text}}; } catch (const DecimalParseError &) { diff --git a/vendor/core/src/core/jsonpointer/position.cc b/vendor/core/src/core/jsonpointer/position.cc index f27ad6caf..23035f573 100644 --- a/vendor/core/src/core/jsonpointer/position.cc +++ b/vendor/core/src/core/jsonpointer/position.cc @@ -8,6 +8,32 @@ #include // std::uint64_t #include // std::optional #include // std::string_view +#include // std::vector + +namespace { + +// A property step and an index step differ in nothing but which of the two +// child maps of a node the step is remembered in, so what a step does with +// what it finds there is spelled out once here. The map is reached through the +// node each time, as taking in a new node may move the ones already held +template +auto descend_into(std::vector &trie, Children Node::*children, + const Key &key, std::size_t ¤t_node) -> void { + const auto match{(trie[current_node].*children).find(key)}; + if (match != (trie[current_node].*children).end()) { + current_node = match->second; + return; + } + + const auto node_index{trie.size()}; + trie.push_back({.position = std::nullopt, + .index_children = {}, + .property_children = {}}); + (trie[current_node].*children).emplace(key, node_index); + current_node = node_index; +} + +} // namespace namespace sourcemeta::core { @@ -32,40 +58,15 @@ auto PointerPositionTracker::ensure_index() const -> void { std::make_pair(event.line, event.column)); switch (event.context) { - case JSON::ParseContext::Property: { + case JSON::ParseContext::Property: assert(event.property != nullptr); - const std::string_view key{*event.property}; - auto iterator{ - this->trie_[current_node].property_children.find(key)}; - if (iterator == this->trie_[current_node].property_children.end()) { - const auto node_index{this->trie_.size()}; - this->trie_.push_back({.position = std::nullopt, - .index_children = {}, - .property_children = {}}); - this->trie_[current_node].property_children.emplace(key, - node_index); - current_node = node_index; - } else { - current_node = iterator->second; - } + descend_into(this->trie_, &TrieNode::property_children, + std::string_view{*event.property}, current_node); break; - } - case JSON::ParseContext::Index: { - auto iterator{ - this->trie_[current_node].index_children.find(event.index)}; - if (iterator == this->trie_[current_node].index_children.end()) { - const auto node_index{this->trie_.size()}; - this->trie_.push_back({.position = std::nullopt, - .index_children = {}, - .property_children = {}}); - this->trie_[current_node].index_children.emplace(event.index, - node_index); - current_node = node_index; - } else { - current_node = iterator->second; - } + case JSON::ParseContext::Index: + descend_into(this->trie_, &TrieNode::index_children, event.index, + current_node); break; - } case JSON::ParseContext::Root: break; } diff --git a/vendor/core/src/core/jsonschema/known_resolver.cmake b/vendor/core/src/core/jsonschema/known_resolver.cmake index 7ffe0dd31..5f0a06904 100644 --- a/vendor/core/src/core/jsonschema/known_resolver.cmake +++ b/vendor/core/src/core/jsonschema/known_resolver.cmake @@ -96,9 +96,23 @@ file(READ "${OPENAPI_3_1_DIR}/meta/2024-10-25" OPENAPI_OAS_3_1_META_2024_10_25) file(READ "${OPENAPI_3_1_DIR}/dialect/2024-10-25" OPENAPI_OAS_3_1_DIALECT_2024_10_25) # OpenAPI v3.0 +# The Schema Object is only published as a definition of the document schema, +# so a dialect for it has to carry that definition along with the ones it +# reaches. Taking those alone leaves behind a document schema that is longer +# than what the strictest compiler allows a single string literal to be set(OPENAPI_3_0_DIR "${PROJECT_SOURCE_DIR}/vendor/openapi/oas/3.0") -file(READ "${OPENAPI_3_0_DIR}/schema/2024-10-18" OPENAPI_OAS_3_0_SCHEMA_2024_10_18) -file(READ "${OPENAPI_3_0_DIR}/schema/2021-09-28" OPENAPI_OAS_3_0_SCHEMA_2021_09_28) +file(READ "${OPENAPI_3_0_DIR}/schema/2024-10-18" OPENAPI_OAS_3_0_DOCUMENT) +string(JSON OPENAPI_OAS_3_0_SCHEMA_2024_10_18 GET "${OPENAPI_OAS_3_0_DOCUMENT}" definitions Schema) +string(JSON OPENAPI_OAS_3_0_REFERENCE_2024_10_18 GET "${OPENAPI_OAS_3_0_DOCUMENT}" definitions Reference) +string(JSON OPENAPI_OAS_3_0_DISCRIMINATOR_2024_10_18 GET "${OPENAPI_OAS_3_0_DOCUMENT}" definitions Discriminator) +string(JSON OPENAPI_OAS_3_0_EXTERNAL_DOCUMENTATION_2024_10_18 GET "${OPENAPI_OAS_3_0_DOCUMENT}" definitions ExternalDocumentation) +string(JSON OPENAPI_OAS_3_0_XML_2024_10_18 GET "${OPENAPI_OAS_3_0_DOCUMENT}" definitions XML) +file(READ "${OPENAPI_3_0_DIR}/schema/2021-09-28" OPENAPI_OAS_3_0_DOCUMENT) +string(JSON OPENAPI_OAS_3_0_SCHEMA_2021_09_28 GET "${OPENAPI_OAS_3_0_DOCUMENT}" definitions Schema) +string(JSON OPENAPI_OAS_3_0_REFERENCE_2021_09_28 GET "${OPENAPI_OAS_3_0_DOCUMENT}" definitions Reference) +string(JSON OPENAPI_OAS_3_0_DISCRIMINATOR_2021_09_28 GET "${OPENAPI_OAS_3_0_DOCUMENT}" definitions Discriminator) +string(JSON OPENAPI_OAS_3_0_EXTERNAL_DOCUMENTATION_2021_09_28 GET "${OPENAPI_OAS_3_0_DOCUMENT}" definitions ExternalDocumentation) +string(JSON OPENAPI_OAS_3_0_XML_2021_09_28 GET "${OPENAPI_OAS_3_0_DOCUMENT}" definitions XML) if(NOT KNOWN_RESOLVER_INPUT) message(FATAL_ERROR "Missing KNOWN_RESOLVER_INPUT") diff --git a/vendor/core/src/core/jsonschema/known_resolver.in.cc b/vendor/core/src/core/jsonschema/known_resolver.in.cc index f490756bc..cd5b48456 100644 --- a/vendor/core/src/core/jsonschema/known_resolver.in.cc +++ b/vendor/core/src/core/jsonschema/known_resolver.in.cc @@ -767,11 +767,11 @@ auto sourcemeta::core::schema_resolver(const std::string_view identifier) return SCHEMA; } // The published document schema describes the Schema Object as one of its - // definitions rather than on its own, and nothing else of it is of use - // here, so it is carried within the dialect instead of being exposed. The - // identifier it declares has to stay for the references it makes to - // itself to keep resolving against its own scope. Note a schema of this - // dialect is either a Schema Object or a Reference Object + // definitions rather than on its own, so the dialect carries that + // definition and the ones it reaches instead of the document being + // exposed. They stay under the identifier the document declares, as that + // is the scope the references between them resolve against. Note a schema + // of this dialect is either a Schema Object or a Reference Object case KnownSchema::OAS_3_0_DIALECT_2024_10_18: { static const auto SCHEMA{sourcemeta::core::parse_json(R"EOF({ "id": "tag:spec.openapis.org,2024-10-18:oas/3.0/dialect", @@ -782,7 +782,17 @@ auto sourcemeta::core::schema_resolver(const std::string_view identifier) { "$ref": "#/definitions/openapi/definitions/Reference" } ], "definitions": { - "openapi": @OPENAPI_OAS_3_0_SCHEMA_2024_10_18@ + "openapi": { + "id": "https://spec.openapis.org/oas/3.0/schema/2024-10-18", + "$schema": "http://json-schema.org/draft-04/schema#", + "definitions": { + "Schema": @OPENAPI_OAS_3_0_SCHEMA_2024_10_18@, + "Reference": @OPENAPI_OAS_3_0_REFERENCE_2024_10_18@, + "Discriminator": @OPENAPI_OAS_3_0_DISCRIMINATOR_2024_10_18@, + "ExternalDocumentation": @OPENAPI_OAS_3_0_EXTERNAL_DOCUMENTATION_2024_10_18@, + "XML": @OPENAPI_OAS_3_0_XML_2024_10_18@ + } + } } })EOF")}; return SCHEMA; @@ -797,7 +807,17 @@ auto sourcemeta::core::schema_resolver(const std::string_view identifier) { "$ref": "#/definitions/openapi/definitions/Reference" } ], "definitions": { - "openapi": @OPENAPI_OAS_3_0_SCHEMA_2021_09_28@ + "openapi": { + "id": "https://spec.openapis.org/oas/3.0/schema/2021-09-28", + "$schema": "http://json-schema.org/draft-04/schema#", + "definitions": { + "Schema": @OPENAPI_OAS_3_0_SCHEMA_2021_09_28@, + "Reference": @OPENAPI_OAS_3_0_REFERENCE_2021_09_28@, + "Discriminator": @OPENAPI_OAS_3_0_DISCRIMINATOR_2021_09_28@, + "ExternalDocumentation": @OPENAPI_OAS_3_0_EXTERNAL_DOCUMENTATION_2021_09_28@, + "XML": @OPENAPI_OAS_3_0_XML_2021_09_28@ + } + } } })EOF")}; return SCHEMA; diff --git a/vendor/core/src/core/jsonschema/known_walker.cc b/vendor/core/src/core/jsonschema/known_walker.cc index a059cbb02..bf7bd5371 100644 --- a/vendor/core/src/core/jsonschema/known_walker.cc +++ b/vendor/core/src/core/jsonschema/known_walker.cc @@ -3767,7 +3767,7 @@ constexpr std::array VARIANTS{{ .secondary = std::nullopt, .result = {SchemaKeywordType::Assertion, Known::OPENAPI_3_0_BASE, - {}, + KEYWORDS_TYPE, {}, INSTANCES_ANY}}, {.vocabulary = Known::JSON_SCHEMA_2020_12_APPLICATOR, diff --git a/vendor/core/src/core/markdown/include/sourcemeta/core/markdown.h b/vendor/core/src/core/markdown/include/sourcemeta/core/markdown.h index 6901d12eb..2dd374aa6 100644 --- a/vendor/core/src/core/markdown/include/sourcemeta/core/markdown.h +++ b/vendor/core/src/core/markdown/include/sourcemeta/core/markdown.h @@ -9,6 +9,9 @@ #include // NOLINTEND(misc-include-cleaner) +#include // std::size_t +#include // std::uint32_t +#include // std::numeric_limits #include // std::string #include // std::string_view @@ -24,6 +27,13 @@ namespace sourcemeta::core { +/// @ingroup markdown +/// The most input bytes accepted when a caller names no bound of its own, +/// which is what the offsets the parser addresses its input through can reach, +/// so a caller may name a smaller bound but never a larger one. +inline constexpr std::size_t MARKDOWN_MAXIMUM_INPUT_BYTES{ + std::numeric_limits::max()}; + /// @ingroup markdown /// Convert a Markdown string to an HTML fragment using GitHub Flavored /// Markdown (GFM) with all standard extensions enabled (tables, autolinks, @@ -35,7 +45,10 @@ namespace sourcemeta::core { /// output far larger than the input, so the conversion throws `MarkdownError` /// once the rendered link references expand past the larger of 16 times the /// input size and 1,048,576 bytes, or once a table inserts more than 524,288 -/// empty cells. For example: +/// empty cells. A bound smaller than the default refuses a larger input +/// outright, counted after a NUL or a malformed byte sequence has been +/// replaced, so a repaired input may exceed a bound the written one meets. +/// For example: /// /// ```cpp /// #include @@ -46,8 +59,9 @@ namespace sourcemeta::core { /// assert(result == "

Hello world

\n"); /// ``` SOURCEMETA_CORE_MARKDOWN_EXPORT -auto markdown_to_html(const std::string_view input, const bool safe = true) - -> std::string; +auto markdown_to_html(const std::string_view input, const bool safe = true, + std::size_t maximum_input_bytes = + MARKDOWN_MAXIMUM_INPUT_BYTES) -> std::string; } // namespace sourcemeta::core diff --git a/vendor/core/src/core/markdown/markdown.cc b/vendor/core/src/core/markdown/markdown.cc index ae2584cb7..37e134019 100644 --- a/vendor/core/src/core/markdown/markdown.cc +++ b/vendor/core/src/core/markdown/markdown.cc @@ -9,9 +9,8 @@ #include "postprocess.h" #include "render.h" +#include // std::min #include // std::size_t -#include // std::uint32_t -#include // std::numeric_limits #include // std::optional #include // std::string #include // std::string_view @@ -60,8 +59,8 @@ auto replace_invalid_characters(const std::string_view input, namespace sourcemeta::core { -auto markdown_to_html(const std::string_view input, const bool safe) - -> std::string { +auto markdown_to_html(const std::string_view input, const bool safe, + const std::size_t maximum_input_bytes) -> std::string { thread_local std::optional state; if (!state.has_value()) { state.emplace(); @@ -80,8 +79,10 @@ auto markdown_to_html(const std::string_view input, const bool safe) source = converter.repaired; } - // The parser addresses the input through 32-bit offsets - if (source.size() > std::numeric_limits::max()) { + // The parser addresses the input through 32-bit offsets, so what a caller + // names only ever tightens the reach those offsets have + if (source.size() > + std::min(maximum_input_bytes, MARKDOWN_MAXIMUM_INPUT_BYTES)) { throw MarkdownError{"The input is larger than the supported size bound"}; } diff --git a/vendor/core/src/core/mcp/headers.cc b/vendor/core/src/core/mcp/headers.cc index 7ac84cef2..5f774c80a 100644 --- a/vendor/core/src/core/mcp/headers.cc +++ b/vendor/core/src/core/mcp/headers.cc @@ -10,6 +10,7 @@ #include #include // std::find +#include // assert #include // std::optional, std::nullopt #include // std::span #include // std::string @@ -285,7 +286,11 @@ auto mcp_make_error_request_meta( version, identifier, JSONRPC_CODE_INVALID_PARAMS, "Invalid params: clientInfo description must be a string"); } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } auto mcp_request_name_from_body(const sourcemeta::core::JSON &envelope) @@ -456,11 +461,11 @@ auto mcp_validate_request_headers( version, identifier, MCP_HEADER_PROTOCOL_VERSION, *protocol_version_header, mcp_protocol_version_string(version)); } - if (meta_status && *meta_status != MCPRequestMetaStatus::Valid) { - return mcp_make_error_request_meta(version, identifier, *meta_status, - *protocol_version_header, - supported_versions); - } + // Every other outcome was reported above, and the one left is only reached + // by a body version that names no revision carrying metadata, which the two + // checks above have already turned down by holding the body to the header + // and the header to the revision this session speaks + assert(!meta_status || *meta_status == MCPRequestMetaStatus::Valid); if (!method_header || !sourcemeta::core::mcp_is_plain_header_value(*method_header)) { return mcp_make_error_header_mismatch(version, identifier, diff --git a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_capabilities.h b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_capabilities.h index 9c317bc8b..2e79054a0 100644 --- a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_capabilities.h +++ b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_capabilities.h @@ -168,9 +168,9 @@ struct MCPServerCapabilities { /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#clientcapabilities -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_parse_client_capabilities(const MCPProtocolVersion version, - const sourcemeta::core::JSON &capabilities) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_parse_client_capabilities(const MCPProtocolVersion version, + const sourcemeta::core::JSON &capabilities) -> MCPClientCapabilities; /// @ingroup mcp @@ -199,9 +199,9 @@ auto mcp_parse_client_capabilities(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#clientcapabilities -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_serialize_client_capabilities( - const MCPProtocolVersion version, const MCPClientCapabilities &capabilities) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_serialize_client_capabilities(const MCPProtocolVersion version, + const MCPClientCapabilities &capabilities) -> sourcemeta::core::JSON; /// @ingroup mcp @@ -226,9 +226,9 @@ auto mcp_serialize_client_capabilities( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#servercapabilities -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_parse_server_capabilities(MCPProtocolVersion version, - const JSON &capabilities) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_parse_server_capabilities(MCPProtocolVersion version, + const JSON &capabilities) -> MCPServerCapabilities; /// @ingroup mcp @@ -252,9 +252,9 @@ auto mcp_parse_server_capabilities(MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#servercapabilities -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_serialize_server_capabilities( - MCPProtocolVersion version, const MCPServerCapabilities &capabilities) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_serialize_server_capabilities(MCPProtocolVersion version, + const MCPServerCapabilities &capabilities) -> JSON; } // namespace sourcemeta::core diff --git a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_error.h b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_error.h index f5333f52f..1878f878c 100644 --- a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_error.h +++ b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_error.h @@ -109,11 +109,11 @@ enum class MCPErrorContext : std::uint8_t { /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/index#responses -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_error(MCPProtocolVersion version, const JSON *identifier, - std::int64_t code, JSON::StringView message, - std::optional data = std::nullopt, - MCPErrorContext context = MCPErrorContext::Request) -> JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_error(MCPProtocolVersion version, const JSON *identifier, + std::int64_t code, JSON::StringView message, + std::optional data = std::nullopt, + MCPErrorContext context = MCPErrorContext::Request) -> JSON; /// @ingroup mcp /// The legacy MCP error code returned when a requested resource cannot be @@ -196,8 +196,9 @@ constexpr std::int64_t MCP_CODE_UNSUPPORTED_PROTOCOL_VERSION{-32022}; /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#server-validation /// https://modelcontextprotocol.io/specification/2026-07-28/basic/index#_meta -constexpr auto mcp_error_code_to_http_status(const MCPProtocolVersion version, - const std::int64_t code) noexcept +[[nodiscard]] constexpr auto +mcp_error_code_to_http_status(const MCPProtocolVersion version, + const std::int64_t code) noexcept -> std::optional { if (version != MCPProtocolVersion::V_2026_07_28) { return std::nullopt; @@ -247,8 +248,8 @@ constexpr auto mcp_error_code_to_http_status(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/index#error-codes -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_error_unsupported_protocol_version( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_error_unsupported_protocol_version( const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, const JSON::StringView requested, const std::span supported) @@ -282,8 +283,8 @@ auto mcp_make_error_unsupported_protocol_version( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/index#error-codes -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_error_missing_required_capability( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_error_missing_required_capability( const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, sourcemeta::core::JSON required_capabilities, const JSON::StringView message) -> sourcemeta::core::JSON; @@ -310,11 +311,9 @@ auto mcp_make_error_missing_required_capability( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#schema-extension -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_error_header_mismatch(const MCPProtocolVersion version, - const sourcemeta::core::JSON *identifier, - const JSON::StringView message) - -> sourcemeta::core::JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_error_header_mismatch( + const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, + const JSON::StringView message) -> sourcemeta::core::JSON; /// @ingroup mcp /// Build a JSON-RPC error response for header mismatch (-32020) with detailed @@ -346,13 +345,10 @@ auto mcp_make_error_header_mismatch(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#schema-extension -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_error_header_mismatch(const MCPProtocolVersion version, - const sourcemeta::core::JSON *identifier, - const JSON::StringView header_name, - const JSON::StringView header_value, - const JSON::StringView body_value) - -> sourcemeta::core::JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_error_header_mismatch( + const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, + const JSON::StringView header_name, const JSON::StringView header_value, + const JSON::StringView body_value) -> sourcemeta::core::JSON; /// @ingroup mcp /// Build a JSON-RPC error response for header mismatch (-32020) reporting an @@ -379,11 +375,9 @@ auto mcp_make_error_header_mismatch(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#schema-extension -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_error_header_mismatch(const MCPProtocolVersion version, - const sourcemeta::core::JSON *identifier, - const JSON::StringView header_name, - const JSON::StringView header_value) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_error_header_mismatch( + const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, + const JSON::StringView header_name, const JSON::StringView header_value) -> sourcemeta::core::JSON; /// @ingroup mcp @@ -414,9 +408,9 @@ auto mcp_make_error_header_mismatch(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/resources#error-handling -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_error_resource_not_found(const MCPProtocolVersion version, - const sourcemeta::core::JSON *identifier) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_error_resource_not_found(const MCPProtocolVersion version, + const sourcemeta::core::JSON *identifier) -> sourcemeta::core::JSON; } // namespace sourcemeta::core diff --git a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_headers.h b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_headers.h index a10fdb6db..54993d054 100644 --- a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_headers.h +++ b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_headers.h @@ -141,8 +141,8 @@ struct MCPRequestMeta { /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/index#_meta -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_validate_request_meta(const sourcemeta::core::JSON &envelope) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_validate_request_meta(const sourcemeta::core::JSON &envelope) -> std::pair>; /// @ingroup mcp @@ -166,8 +166,8 @@ auto mcp_validate_request_meta(const sourcemeta::core::JSON &envelope) /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/index#_meta -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_validate_request_parameters(const JSON ¶meters) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_validate_request_parameters(const JSON ¶meters) -> std::pair>; /// @ingroup mcp @@ -216,8 +216,7 @@ auto mcp_validate_request_parameters(const JSON ¶meters) /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/index#error-codes -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_error_request_meta( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_error_request_meta( const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, const MCPRequestMetaStatus status, const JSON::StringView requested, const std::span supported) @@ -242,8 +241,8 @@ auto mcp_make_error_request_meta( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#standard-request-headers -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_request_name_from_body(const sourcemeta::core::JSON &envelope) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_request_name_from_body(const sourcemeta::core::JSON &envelope) -> std::optional; /// @ingroup mcp @@ -285,8 +284,7 @@ auto mcp_request_name_from_body(const sourcemeta::core::JSON &envelope) /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#server-validation -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_validate_request_headers( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_validate_request_headers( const MCPProtocolVersion version, const std::optional &protocol_version_header, const std::optional &method_header, @@ -316,8 +314,8 @@ auto mcp_validate_request_headers( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#value-encoding -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_encode_header_value(JSON::StringView value) -> std::string; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_encode_header_value(JSON::StringView value) -> std::string; /// @ingroup mcp /// Validate a borrowed HTTP header collection. Names are case insensitive. @@ -363,8 +361,7 @@ auto mcp_encode_header_value(JSON::StringView value) -> std::string; /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#server-validation -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_validate_request_headers( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_validate_request_headers( MCPProtocolVersion version, std::span> headers, const JSON &envelope, std::span supported_versions) @@ -442,9 +439,9 @@ struct MCPHeaderParameter { /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#schema-extension -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_parameter_headers(std::span parameters, - const JSON &arguments) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_parameter_headers(std::span parameters, + const JSON &arguments) -> std::vector>; /// @ingroup mcp @@ -478,8 +475,7 @@ auto mcp_make_parameter_headers(std::span parameters, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#server-validation -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_validate_parameter_headers( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_validate_parameter_headers( MCPProtocolVersion version, const JSON &identifier, std::span parameters, const JSON &arguments, std::span> headers) diff --git a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_logging.h b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_logging.h index 89b77f9ef..9c7b5e696 100644 --- a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_logging.h +++ b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_logging.h @@ -55,8 +55,8 @@ enum class MCPLogLevel : std::uint8_t { /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/logging -constexpr auto mcp_log_level_string(const MCPLogLevel level) noexcept - -> JSON::StringView { +[[nodiscard]] constexpr auto +mcp_log_level_string(const MCPLogLevel level) noexcept -> JSON::StringView { switch (level) { case MCPLogLevel::Debug: return "debug"; @@ -75,7 +75,11 @@ constexpr auto mcp_log_level_string(const MCPLogLevel level) noexcept case MCPLogLevel::Emergency: return "emergency"; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } /// @ingroup mcp @@ -95,7 +99,8 @@ constexpr auto mcp_log_level_string(const MCPLogLevel level) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/logging -constexpr auto mcp_resolve_log_level(const JSON::StringView value) noexcept +[[nodiscard]] constexpr auto +mcp_resolve_log_level(const JSON::StringView value) noexcept -> std::optional { constexpr std::array LEVELS{ {MCPLogLevel::Debug, MCPLogLevel::Info, MCPLogLevel::Notice, @@ -131,9 +136,9 @@ constexpr auto mcp_resolve_log_level(const JSON::StringView value) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/logging -constexpr auto mcp_log_level_enabled(const MCPLogLevel level, - const MCPLogLevel threshold) noexcept - -> bool { +[[nodiscard]] constexpr auto +mcp_log_level_enabled(const MCPLogLevel level, + const MCPLogLevel threshold) noexcept -> bool { return level >= threshold; } diff --git a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_protocol.h b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_protocol.h index fc628e644..0b4260cea 100644 --- a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_protocol.h +++ b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_protocol.h @@ -384,7 +384,7 @@ constexpr JSON::StringView MCP_METHOD_TASKS_RESULT{"tasks/result"}; /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning -constexpr auto +[[nodiscard]] constexpr auto mcp_protocol_version_string(const MCPProtocolVersion version) noexcept -> JSON::StringView { switch (version) { @@ -397,7 +397,11 @@ mcp_protocol_version_string(const MCPProtocolVersion version) noexcept case MCPProtocolVersion::V_2026_07_28: return MCP_PROTOCOL_VERSION_2026_07_28; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } /// @ingroup mcp @@ -417,7 +421,7 @@ mcp_protocol_version_string(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning -constexpr auto +[[nodiscard]] constexpr auto mcp_resolve_protocol_version(const JSON::StringView value) noexcept -> std::optional { if (value == MCP_PROTOCOL_VERSION_2026_07_28) { @@ -454,7 +458,7 @@ mcp_resolve_protocol_version(const JSON::StringView value) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning -constexpr auto +[[nodiscard]] constexpr auto mcp_protocol_version_at_least(const MCPProtocolVersion current, const MCPProtocolVersion minimum) noexcept -> bool { @@ -476,7 +480,7 @@ mcp_protocol_version_at_least(const MCPProtocolVersion current, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning -constexpr auto +[[nodiscard]] constexpr auto mcp_protocol_version_is_valid(const JSON::StringView value) noexcept -> bool { return mcp_resolve_protocol_version(value).has_value(); } @@ -498,7 +502,7 @@ mcp_protocol_version_is_valid(const JSON::StringView value) noexcept -> bool { /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/lifecycle -constexpr auto +[[nodiscard]] constexpr auto mcp_uses_initialization_handshake(const MCPProtocolVersion version) noexcept -> bool { return version != MCPProtocolVersion::V_2026_07_28; @@ -520,8 +524,8 @@ mcp_uses_initialization_handshake(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/lifecycle -constexpr auto mcp_supports_ping(const MCPProtocolVersion version) noexcept - -> bool { +[[nodiscard]] constexpr auto +mcp_supports_ping(const MCPProtocolVersion version) noexcept -> bool { return version != MCPProtocolVersion::V_2026_07_28; } @@ -542,7 +546,7 @@ constexpr auto mcp_supports_ping(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/index#_meta -constexpr auto +[[nodiscard]] constexpr auto mcp_requires_request_meta(const MCPProtocolVersion version) noexcept -> bool { return version == MCPProtocolVersion::V_2026_07_28; } @@ -564,7 +568,7 @@ mcp_requires_request_meta(const MCPProtocolVersion version) noexcept -> bool { /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema -constexpr auto +[[nodiscard]] constexpr auto mcp_requires_result_type(const MCPProtocolVersion version) noexcept -> bool { return version == MCPProtocolVersion::V_2026_07_28; } @@ -586,7 +590,7 @@ mcp_requires_result_type(const MCPProtocolVersion version) noexcept -> bool { /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results -constexpr auto +[[nodiscard]] constexpr auto mcp_requires_cacheable_metadata(const MCPProtocolVersion version) noexcept -> bool { return version == MCPProtocolVersion::V_2026_07_28; @@ -609,7 +613,7 @@ mcp_requires_cacheable_metadata(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/discover -constexpr auto +[[nodiscard]] constexpr auto mcp_supports_server_discover(const MCPProtocolVersion version) noexcept -> bool { return version == MCPProtocolVersion::V_2026_07_28; @@ -632,7 +636,7 @@ mcp_supports_server_discover(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions -constexpr auto +[[nodiscard]] constexpr auto mcp_supports_subscriptions_listen(const MCPProtocolVersion version) noexcept -> bool { return version == MCPProtocolVersion::V_2026_07_28; @@ -655,8 +659,8 @@ mcp_supports_subscriptions_listen(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr -constexpr auto mcp_supports_mrtr(const MCPProtocolVersion version) noexcept - -> bool { +[[nodiscard]] constexpr auto +mcp_supports_mrtr(const MCPProtocolVersion version) noexcept -> bool { return version == MCPProtocolVersion::V_2026_07_28; } @@ -677,7 +681,7 @@ constexpr auto mcp_supports_mrtr(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http -constexpr auto +[[nodiscard]] constexpr auto mcp_supports_protocol_sessions(const MCPProtocolVersion version) noexcept -> bool { return version != MCPProtocolVersion::V_2026_07_28; @@ -700,7 +704,7 @@ mcp_supports_protocol_sessions(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/tools -constexpr auto +[[nodiscard]] constexpr auto mcp_supports_output_schema(const MCPProtocolVersion version) noexcept -> bool { return mcp_protocol_version_at_least(version, MCPProtocolVersion::V_2025_06_18); @@ -722,7 +726,7 @@ mcp_supports_output_schema(const MCPProtocolVersion version) noexcept -> bool { /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/tools -constexpr auto +[[nodiscard]] constexpr auto mcp_supports_structured_content(const MCPProtocolVersion version) noexcept -> bool { return mcp_protocol_version_at_least(version, @@ -745,7 +749,7 @@ mcp_supports_structured_content(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema -constexpr auto +[[nodiscard]] constexpr auto mcp_supports_resource_link_content(const MCPProtocolVersion version) noexcept -> bool { return mcp_protocol_version_at_least(version, @@ -768,7 +772,7 @@ mcp_supports_resource_link_content(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema -constexpr auto +[[nodiscard]] constexpr auto mcp_supports_implementation_title(const MCPProtocolVersion version) noexcept -> bool { return mcp_protocol_version_at_least(version, @@ -792,7 +796,7 @@ mcp_supports_implementation_title(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema -constexpr auto mcp_supports_implementation_description( +[[nodiscard]] constexpr auto mcp_supports_implementation_description( const MCPProtocolVersion version) noexcept -> bool { return mcp_protocol_version_at_least(version, MCPProtocolVersion::V_2025_11_25); @@ -815,7 +819,7 @@ constexpr auto mcp_supports_implementation_description( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema -constexpr auto mcp_supports_implementation_website_url( +[[nodiscard]] constexpr auto mcp_supports_implementation_website_url( const MCPProtocolVersion version) noexcept -> bool { return mcp_protocol_version_at_least(version, MCPProtocolVersion::V_2025_11_25); @@ -837,7 +841,7 @@ constexpr auto mcp_supports_implementation_website_url( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http -constexpr auto +[[nodiscard]] constexpr auto mcp_supports_jsonrpc_batching(const MCPProtocolVersion version) noexcept -> bool { return version == MCPProtocolVersion::V_2025_03_26; @@ -859,9 +863,9 @@ mcp_supports_jsonrpc_batching(const MCPProtocolVersion version) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema -constexpr auto mcp_is_request_method(const MCPProtocolVersion version, - const JSON::StringView method) noexcept - -> bool { +[[nodiscard]] constexpr auto +mcp_is_request_method(const MCPProtocolVersion version, + const JSON::StringView method) noexcept -> bool { switch (version) { case MCPProtocolVersion::V_2025_03_26: case MCPProtocolVersion::V_2025_06_18: @@ -903,7 +907,11 @@ constexpr auto mcp_is_request_method(const MCPProtocolVersion version, method == MCP_METHOD_SUBSCRIPTIONS_LISTEN || method == MCP_METHOD_TOOLS_CALL || method == MCP_METHOD_TOOLS_LIST; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } /// @ingroup mcp @@ -923,7 +931,7 @@ constexpr auto mcp_is_request_method(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema -constexpr auto +[[nodiscard]] constexpr auto mcp_is_server_request_method(const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool { switch (version) { @@ -945,7 +953,11 @@ mcp_is_server_request_method(const MCPProtocolVersion version, case MCPProtocolVersion::V_2026_07_28: return false; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } /// @ingroup mcp @@ -966,7 +978,7 @@ mcp_is_server_request_method(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema -constexpr auto +[[nodiscard]] constexpr auto mcp_is_notification_method(const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool { switch (version) { @@ -1003,7 +1015,11 @@ mcp_is_notification_method(const MCPProtocolVersion version, method == MCP_METHOD_NOTIFICATIONS_SUBSCRIPTIONS_ACKNOWLEDGED || method == MCP_METHOD_NOTIFICATIONS_TOOLS_LIST_CHANGED; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } /// @ingroup mcp @@ -1024,7 +1040,7 @@ mcp_is_notification_method(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr -constexpr auto +[[nodiscard]] constexpr auto mcp_is_input_request_method(const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool { switch (version) { @@ -1037,7 +1053,11 @@ mcp_is_input_request_method(const MCPProtocolVersion version, method == MCP_METHOD_ROOTS_LIST || method == MCP_METHOD_SAMPLING_CREATE_MESSAGE; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } /// @ingroup mcp @@ -1058,9 +1078,9 @@ mcp_is_input_request_method(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema -constexpr auto mcp_supports_method(const MCPProtocolVersion version, - const JSON::StringView method) noexcept - -> bool { +[[nodiscard]] constexpr auto +mcp_supports_method(const MCPProtocolVersion version, + const JSON::StringView method) noexcept -> bool { switch (version) { case MCPProtocolVersion::V_2025_03_26: return method == MCP_METHOD_COMPLETION_COMPLETE || @@ -1161,7 +1181,11 @@ constexpr auto mcp_supports_method(const MCPProtocolVersion version, method == MCP_METHOD_SUBSCRIPTIONS_LISTEN || method == MCP_METHOD_TOOLS_CALL || method == MCP_METHOD_TOOLS_LIST; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } /// @ingroup mcp @@ -1178,8 +1202,8 @@ constexpr auto mcp_supports_method(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr -constexpr auto mcp_is_mrtr_method(const JSON::StringView method) noexcept - -> bool { +[[nodiscard]] constexpr auto +mcp_is_mrtr_method(const JSON::StringView method) noexcept -> bool { return method == MCP_METHOD_TOOLS_CALL || method == MCP_METHOD_RESOURCES_READ || method == MCP_METHOD_PROMPTS_GET; @@ -1199,8 +1223,8 @@ constexpr auto mcp_is_mrtr_method(const JSON::StringView method) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results -constexpr auto mcp_is_cacheable_method(const JSON::StringView method) noexcept - -> bool { +[[nodiscard]] constexpr auto +mcp_is_cacheable_method(const JSON::StringView method) noexcept -> bool { return method == MCP_METHOD_SERVER_DISCOVER || method == MCP_METHOD_TOOLS_LIST || method == MCP_METHOD_PROMPTS_LIST || method == MCP_METHOD_RESOURCES_LIST || @@ -1226,7 +1250,7 @@ constexpr auto mcp_is_cacheable_method(const JSON::StringView method) noexcept /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema -constexpr auto +[[nodiscard]] constexpr auto mcp_is_client_notification_method(MCPProtocolVersion version, JSON::StringView method) noexcept -> bool { switch (version) { @@ -1245,7 +1269,11 @@ mcp_is_client_notification_method(MCPProtocolVersion version, case MCPProtocolVersion::V_2026_07_28: return method == "notifications/cancelled"; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } /// @ingroup mcp @@ -1266,7 +1294,7 @@ mcp_is_client_notification_method(MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema -constexpr auto +[[nodiscard]] constexpr auto mcp_is_server_notification_method(MCPProtocolVersion version, JSON::StringView method) noexcept -> bool { switch (version) { @@ -1299,7 +1327,11 @@ mcp_is_server_notification_method(MCPProtocolVersion version, method == "notifications/tools/list_changed" || method == "notifications/message"; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } } // namespace sourcemeta::core diff --git a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_results.h b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_results.h index d32daf530..1bd364735 100644 --- a/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_results.h +++ b/vendor/core/src/core/mcp/include/sourcemeta/core/mcp_results.h @@ -45,15 +45,19 @@ enum class MCPCacheScope : std::uint8_t { /// assert(sourcemeta::core::mcp_cache_scope_string( /// sourcemeta::core::MCPCacheScope::Private) == "private"); /// ``` -constexpr auto mcp_cache_scope_string(const MCPCacheScope scope) noexcept - -> JSON::StringView { +[[nodiscard]] constexpr auto +mcp_cache_scope_string(const MCPCacheScope scope) noexcept -> JSON::StringView { switch (scope) { case MCPCacheScope::Public: return "public"; case MCPCacheScope::Private: return "private"; } + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) std::unreachable(); +#endif } /// @ingroup mcp @@ -69,7 +73,8 @@ constexpr auto mcp_cache_scope_string(const MCPCacheScope scope) noexcept /// sourcemeta::core::MCPCacheScope::Private); /// assert(!sourcemeta::core::mcp_resolve_cache_scope("shared").has_value()); /// ``` -constexpr auto mcp_resolve_cache_scope(const JSON::StringView scope) noexcept +[[nodiscard]] constexpr auto +mcp_resolve_cache_scope(const JSON::StringView scope) noexcept -> std::optional { if (scope == "public") { return MCPCacheScope::Public; @@ -179,9 +184,9 @@ struct MCPDescriptorPresentation { /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#annotations -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_serialize_resource_annotations( - MCPProtocolVersion version, const MCPResourceAnnotations &annotations) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_serialize_resource_annotations(MCPProtocolVersion version, + const MCPResourceAnnotations &annotations) -> JSON; /// @ingroup mcp @@ -211,11 +216,10 @@ auto mcp_serialize_resource_annotations( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#imagecontent -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_image_block(MCPProtocolVersion version, JSON::StringView data, - JSON::StringView mime_type, - const MCPResourceAnnotations &annotations = {}) - -> JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_image_block(MCPProtocolVersion version, JSON::StringView data, + JSON::StringView mime_type, + const MCPResourceAnnotations &annotations = {}) -> JSON; /// @ingroup mcp /// Build a base64 audio block, with the same contracts as the image builder. /// For example: @@ -236,11 +240,10 @@ auto mcp_make_image_block(MCPProtocolVersion version, JSON::StringView data, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#audiocontent -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_audio_block(MCPProtocolVersion version, JSON::StringView data, - JSON::StringView mime_type, - const MCPResourceAnnotations &annotations = {}) - -> JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_audio_block(MCPProtocolVersion version, JSON::StringView data, + JSON::StringView mime_type, + const MCPResourceAnnotations &annotations = {}) -> JSON; /// @ingroup mcp /// Embed a checked text/blob resource-content entry in a content block. For /// example: @@ -265,9 +268,9 @@ auto mcp_make_audio_block(MCPProtocolVersion version, JSON::StringView data, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#embeddedresource -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_embedded_resource(MCPProtocolVersion version, JSON resource, - const MCPResourceAnnotations &annotations = {}) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_embedded_resource(MCPProtocolVersion version, JSON resource, + const MCPResourceAnnotations &annotations = {}) -> JSON; /// @ingroup mcp /// Build a blob resource-content entry. The caller supplies base64-encoded @@ -288,10 +291,9 @@ auto mcp_make_embedded_resource(MCPProtocolVersion version, JSON resource, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#blobresourcecontents -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_resource_blob_content(JSON::StringView uri, - JSON::StringView mime_type, - JSON::StringView blob) -> JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_resource_blob_content(JSON::StringView uri, JSON::StringView mime_type, + JSON::StringView blob) -> JSON; /// @ingroup mcp /// Build an MCP `text` content block carrying the given text payload. For /// example: @@ -309,8 +311,8 @@ auto mcp_make_resource_blob_content(JSON::StringView uri, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#textcontent -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_text_block(const JSON::StringView text) -> sourcemeta::core::JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_text_block(const JSON::StringView text) -> sourcemeta::core::JSON; /// @ingroup mcp /// Build an MCP content block referencing a resource by URI. This block type @@ -335,13 +337,10 @@ auto mcp_make_text_block(const JSON::StringView text) -> sourcemeta::core::JSON; /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#resourcelink -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_resource_link(const MCPProtocolVersion version, - const JSON::StringView uri, - const JSON::StringView name, - const JSON::StringView mime_type = {}, - const JSON::StringView description = {}) - -> sourcemeta::core::JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource_link( + const MCPProtocolVersion version, const JSON::StringView uri, + const JSON::StringView name, const JSON::StringView mime_type = {}, + const JSON::StringView description = {}) -> sourcemeta::core::JSON; /// @ingroup mcp /// Decorate a successful MCP result object with version-appropriate envelope @@ -369,8 +368,7 @@ auto mcp_make_resource_link(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#result -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_decorate_result( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_decorate_result( const MCPProtocolVersion version, sourcemeta::core::JSON result, const std::optional &server_info = std::nullopt) -> sourcemeta::core::JSON; @@ -399,11 +397,9 @@ auto mcp_decorate_result( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_decorate_cacheable_result(const MCPProtocolVersion version, - sourcemeta::core::JSON result, - const MCPCachePolicy &cache_policy, - const JSON::StringView method) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_decorate_cacheable_result( + const MCPProtocolVersion version, sourcemeta::core::JSON result, + const MCPCachePolicy &cache_policy, const JSON::StringView method) -> sourcemeta::core::JSON; /// @ingroup mcp @@ -435,8 +431,7 @@ auto mcp_decorate_cacheable_result(const MCPProtocolVersion version, /// https://modelcontextprotocol.io/specification/2026-07-28/schema#emptyresult /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#jsonrpcresultresponse -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_empty_response( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_empty_response( const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const std::optional &server_info = std::nullopt) -> sourcemeta::core::JSON; @@ -470,8 +465,7 @@ auto mcp_make_empty_response( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/tools -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_tool_success( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_tool_success( const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, sourcemeta::core::JSON result, const std::optional &server_info = std::nullopt) @@ -507,8 +501,7 @@ auto mcp_make_tool_success( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/tools -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_tool_success( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_tool_success( const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, sourcemeta::core::JSON structured, sourcemeta::core::JSON content_blocks, const std::optional &server_info = std::nullopt) @@ -539,8 +532,7 @@ auto mcp_make_tool_success( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/tools#error-handling -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_tool_error( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_tool_error( const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const JSON::StringView message, const std::optional &server_info = std::nullopt) @@ -567,15 +559,14 @@ auto mcp_make_tool_error( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#resource -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_resource(const MCPProtocolVersion version, - const JSON::StringView uri, const JSON::StringView name, - const JSON::StringView mime_type, - const JSON::StringView description = {}, - const std::optional size = std::nullopt, - const std::optional priority = std::nullopt, - const MCPDescriptorPresentation &presentation = {}, - const MCPResourceAnnotations &annotations = {}) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_resource(const MCPProtocolVersion version, const JSON::StringView uri, + const JSON::StringView name, const JSON::StringView mime_type, + const JSON::StringView description = {}, + const std::optional size = std::nullopt, + const std::optional priority = std::nullopt, + const MCPDescriptorPresentation &presentation = {}, + const MCPResourceAnnotations &annotations = {}) -> sourcemeta::core::JSON; /// @ingroup mcp @@ -597,11 +588,9 @@ auto mcp_make_resource(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#textresourcecontents -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_resource_text_content(const JSON::StringView uri, - const JSON::StringView mime_type, - const JSON::StringView text) - -> sourcemeta::core::JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource_text_content( + const JSON::StringView uri, const JSON::StringView mime_type, + const JSON::StringView text) -> sourcemeta::core::JSON; /// @ingroup mcp /// Wrap a pre-built array of content entries into the MCP `resources/read` @@ -631,11 +620,9 @@ auto mcp_make_resource_text_content(const JSON::StringView uri, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/resources -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_resources_read_result(const MCPProtocolVersion version, - sourcemeta::core::JSON contents, - const MCPCachePolicy &cache_policy) - -> sourcemeta::core::JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resources_read_result( + const MCPProtocolVersion version, sourcemeta::core::JSON contents, + const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON; /// @ingroup mcp /// Build a single entry for an MCP `resources/templates/list` response. For @@ -659,8 +646,7 @@ auto mcp_make_resources_read_result(const MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#resourcetemplate -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_resource_template( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource_template( const MCPProtocolVersion version, const JSON::StringView uri_template, const JSON::StringView name, const JSON::StringView description, const JSON::StringView mime_type, @@ -698,8 +684,7 @@ auto mcp_make_resource_template( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#tool -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_tool_descriptor( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_tool_descriptor( const MCPProtocolVersion version, const JSON::StringView name, const JSON::StringView description, sourcemeta::core::JSON input_schema, std::optional output_schema = std::nullopt, @@ -731,8 +716,7 @@ auto mcp_make_tool_descriptor( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_tools_list_result( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_tools_list_result( const MCPProtocolVersion version, sourcemeta::core::JSON tools, const std::optional next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON; @@ -767,8 +751,7 @@ auto mcp_make_tools_list_result( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_resources_list_result( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resources_list_result( const MCPProtocolVersion version, sourcemeta::core::JSON resources, const std::optional next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON; @@ -797,8 +780,8 @@ auto mcp_make_resources_list_result( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_resource_templates_list_result( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_resource_templates_list_result( const MCPProtocolVersion version, sourcemeta::core::JSON resource_templates, const std::optional next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON; @@ -829,8 +812,7 @@ auto mcp_make_resource_templates_list_result( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_prompts_list_result( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_prompts_list_result( const MCPProtocolVersion version, sourcemeta::core::JSON prompts, const std::optional next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON; @@ -865,9 +847,9 @@ auto mcp_make_prompts_list_result( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/prompts -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_prompts_get_result(MCPProtocolVersion version, - JSON::StringView description, JSON messages) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_prompts_get_result(MCPProtocolVersion version, + JSON::StringView description, JSON messages) -> JSON; /// @ingroup mcp @@ -889,10 +871,10 @@ auto mcp_make_prompts_get_result(MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#completeresult -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_completion_result(MCPProtocolVersion version, JSON values, - std::optional total, - std::optional has_more) -> JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_completion_result(MCPProtocolVersion version, JSON values, + std::optional total, + std::optional has_more) -> JSON; /// @ingroup mcp /// Serialize a complete MCP response for one of the six cacheable operations. @@ -940,6 +922,25 @@ auto mcp_write_result( std::optional cache_policy, std::optional server_info = std::nullopt) -> void; +/// @ingroup mcp +/// Serialize a complete MCP response for one of the six cacheable operations +/// using move semantics, decorating the provided result in-place. +/// A cache policy is mandatory for 2026-07-28. Pass `std::nullopt` for legacy +/// responses. A precomputed discovery result is held to the same rules as the +/// builder that produces one, so its advertised revisions must be non-empty, +/// must include the revision being served, and must each be one this library +/// models. +/// This writes JSON only. Stdio callers must append a newline themselves. +/// +/// @see +/// https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results +SOURCEMETA_CORE_MCP_EXPORT +auto mcp_write_result( + std::ostream &stream, MCPProtocolVersion version, JSON::StringView method, + const JSON &identifier, JSON &&result, + std::optional cache_policy, + std::optional server_info = std::nullopt) -> void; + /// @ingroup mcp /// Build the JSON-RPC envelope returned in response to an MCP `initialize` /// request. The revision is the one the client asked for when the server @@ -1001,8 +1002,7 @@ auto mcp_write_result( /// /// @see /// https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle#initialization -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_initialize_response( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_initialize_response( const sourcemeta::core::JSON &request, const MCPServerCapabilities &capabilities, const MCPImplementation &server, const std::span supported_versions, @@ -1041,8 +1041,7 @@ auto mcp_make_initialize_response( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/schema#discoverresult -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_server_discover_response( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_server_discover_response( const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const MCPServerCapabilities &capabilities, const MCPImplementation &server, const std::span supported_versions, @@ -1094,8 +1093,7 @@ auto mcp_make_server_discover_response( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr#supported-requests -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_input_required_response( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_input_required_response( const MCPProtocolVersion version, const JSON::StringView method, const sourcemeta::core::JSON &identifier, std::optional input_requests, @@ -1132,9 +1130,9 @@ auto mcp_make_input_required_response( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_request_input_responses(MCPProtocolVersion version, - const sourcemeta::core::JSON &envelope) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_request_input_responses(MCPProtocolVersion version, + const sourcemeta::core::JSON &envelope) -> const sourcemeta::core::JSON *; /// @ingroup mcp @@ -1158,9 +1156,9 @@ auto mcp_request_input_responses(MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_request_state(MCPProtocolVersion version, - const sourcemeta::core::JSON &envelope) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_request_state(MCPProtocolVersion version, + const sourcemeta::core::JSON &envelope) -> std::optional; /// @ingroup mcp @@ -1211,9 +1209,9 @@ struct MCPSubscriptionFilter { /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_parse_subscription_filter(MCPProtocolVersion version, - const JSON ¶meters) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_parse_subscription_filter(MCPProtocolVersion version, + const JSON ¶meters) -> std::optional; /// @ingroup mcp @@ -1238,9 +1236,9 @@ auto mcp_parse_subscription_filter(MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_intersect_subscription_filters(const MCPSubscriptionFilter &requested, - const MCPSubscriptionFilter &supported) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_intersect_subscription_filters(const MCPSubscriptionFilter &requested, + const MCPSubscriptionFilter &supported) -> MCPSubscriptionFilter; /// @ingroup mcp @@ -1265,8 +1263,8 @@ auto mcp_intersect_subscription_filters(const MCPSubscriptionFilter &requested, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/index#result-responses -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_result_type(const JSON &result) -> std::optional; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_result_type(const JSON &result) -> std::optional; /// @ingroup mcp /// Recognize base and explicitly negotiated extension result types. The @@ -1295,8 +1293,7 @@ auto mcp_result_type(const JSON &result) -> std::optional; /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/index#result-responses -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_resolve_result_type( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto mcp_resolve_result_type( MCPProtocolVersion version, const JSON &result, std::span supported_extension_types = {}) -> std::optional; @@ -1340,10 +1337,9 @@ auto mcp_resolve_result_type( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr#client-requirements-basic-workflow -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_validate_continuation(MCPProtocolVersion version, - const JSON ¶meters, - const JSON &input_requests) -> bool; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_validate_continuation(MCPProtocolVersion version, const JSON ¶meters, + const JSON &input_requests) -> bool; /// @ingroup mcp /// Check continuation fields and the state token, where the expected state @@ -1378,11 +1374,10 @@ auto mcp_validate_continuation(MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_validate_continuation(MCPProtocolVersion version, - const JSON ¶meters, - const JSON &input_requests, - std::optional expected_state) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_validate_continuation(MCPProtocolVersion version, const JSON ¶meters, + const JSON &input_requests, + std::optional expected_state) -> bool; /// @ingroup mcp @@ -1415,13 +1410,12 @@ auto mcp_validate_continuation(MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_notification(MCPProtocolVersion version, bool from_server, - JSON::StringView method, JSON parameters, - std::optional subscription_id, - const MCPSubscriptionFilter *acknowledged = nullptr, - const MCPRequestMeta *request_context = nullptr) - -> JSON; +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_notification(MCPProtocolVersion version, bool from_server, + JSON::StringView method, JSON parameters, + std::optional subscription_id, + const MCPSubscriptionFilter *acknowledged = nullptr, + const MCPRequestMeta *request_context = nullptr) -> JSON; /// @ingroup mcp /// Build an acknowledgement notification for `subscriptions/listen` with a @@ -1450,8 +1444,8 @@ auto mcp_make_notification(MCPProtocolVersion version, bool from_server, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_subscription_acknowledged_notification( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_subscription_acknowledged_notification( const MCPProtocolVersion version, const sourcemeta::core::JSON &subscription_id, const MCPSubscriptionFilter &requested, @@ -1482,8 +1476,8 @@ auto mcp_make_subscription_acknowledged_notification( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_subscription_acknowledged_notification( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_subscription_acknowledged_notification( const MCPProtocolVersion version, const JSON::StringView subscription_id, const MCPSubscriptionFilter &requested, const MCPSubscriptionFilter &supported) -> sourcemeta::core::JSON; @@ -1504,8 +1498,8 @@ auto mcp_make_subscription_acknowledged_notification( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_make_subscription_close_response( +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_make_subscription_close_response( const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const std::optional &server_info = std::nullopt) -> sourcemeta::core::JSON; @@ -1533,9 +1527,9 @@ auto mcp_make_subscription_close_response( /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_request_subscription_id(MCPProtocolVersion version, - const sourcemeta::core::JSON &envelope) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_request_subscription_id(MCPProtocolVersion version, + const sourcemeta::core::JSON &envelope) -> const sourcemeta::core::JSON *; /// @ingroup mcp @@ -1560,8 +1554,8 @@ auto mcp_request_subscription_id(MCPProtocolVersion version, /// /// @see /// https://modelcontextprotocol.io/specification/2026-07-28/server/tools -SOURCEMETA_CORE_MCP_EXPORT -auto mcp_tool_call_arguments(const sourcemeta::core::JSON &envelope) +[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT auto +mcp_tool_call_arguments(const sourcemeta::core::JSON &envelope) -> const sourcemeta::core::JSON *; } // namespace sourcemeta::core diff --git a/vendor/core/src/core/mcp/notifications.cc b/vendor/core/src/core/mcp/notifications.cc index a4ae2bac2..111a4001f 100644 --- a/vendor/core/src/core/mcp/notifications.cc +++ b/vendor/core/src/core/mcp/notifications.cc @@ -206,20 +206,20 @@ auto mcp_make_notification(const MCPProtocolVersion version, } else if (method == MCP_METHOD_NOTIFICATIONS_MESSAGE) { const auto *level{ parameters.try_at("level", sourcemeta::core::MCP_HASH_LEVEL)}; + const auto resolved_level{(level != nullptr && level->is_string()) + ? mcp_resolve_log_level(level->to_string()) + : std::nullopt}; internal::require( - (level != nullptr) && level->is_string() && - internal::valid_log_level(level->to_string()) && + resolved_level.has_value() && parameters.defines("data", sourcemeta::core::MCP_HASH_DATA) && optional_string(parameters, "logger", sourcemeta::core::MCP_HASH_LOGGER), "Invalid logging notification"); if (version == MCPProtocolVersion::V_2026_07_28 && from_server) { const auto threshold{mcp_resolve_log_level(*request_context->log_level)}; - internal::require( - threshold.has_value() && - mcp_log_level_enabled(*mcp_resolve_log_level(level->to_string()), - *threshold), - "Logging notification is below the request threshold"); + internal::require(threshold.has_value() && + mcp_log_level_enabled(*resolved_level, *threshold), + "Logging notification is below the request threshold"); } } else if (method == MCP_METHOD_NOTIFICATIONS_CANCELLED) { const auto *identifier{ diff --git a/vendor/core/src/core/mcp/parameter_headers.cc b/vendor/core/src/core/mcp/parameter_headers.cc index a67114e4b..877989dfa 100644 --- a/vendor/core/src/core/mcp/parameter_headers.cc +++ b/vendor/core/src/core/mcp/parameter_headers.cc @@ -64,8 +64,15 @@ auto require_parameters(const std::span parameters) auto safe_parameter(const JSON &value, const MCPHeaderParameter ¶meter) -> bool { if (parameter.type == JSON::Type::Integer) { - return value.is_integral() && value >= JSON{INT64_C(-9007199254740991)} && - value <= JSON{INT64_C(9007199254740991)}; + if (value.is_integer()) { + const auto integer{value.to_integer()}; + return integer >= INT64_C(-9007199254740991) && + integer <= INT64_C(9007199254740991); + } + static const JSON MIN_SAFE_INTEGER{INT64_C(-9007199254740991)}; + static const JSON MAX_SAFE_INTEGER{INT64_C(9007199254740991)}; + return value.is_integral() && value >= MIN_SAFE_INTEGER && + value <= MAX_SAFE_INTEGER; } return value.type() == parameter.type; } diff --git a/vendor/core/src/core/mcp/results.cc b/vendor/core/src/core/mcp/results.cc index d5f521d30..eee63d2b7 100644 --- a/vendor/core/src/core/mcp/results.cc +++ b/vendor/core/src/core/mcp/results.cc @@ -207,14 +207,8 @@ namespace { // is reachable from the interim and subscription results too, whose own result // type rules out the complete-result decorator // https://modelcontextprotocol.io/specification/2026-07-28/basic/index#responses -auto attach_server_info(const MCPProtocolVersion version, - sourcemeta::core::JSON &result, - const std::optional &server_info) - -> void { - if (!server_info.has_value() || !mcp_requires_result_type(version)) { - return; - } - auto info{internal::make_implementation(version, *server_info)}; +auto attach_server_info(sourcemeta::core::JSON &result, + sourcemeta::core::JSON &&info) -> void { if (auto *meta{result.try_at("_meta", MCP_HASH_META)}; meta != nullptr && meta->is_object()) { // Caller-supplied metadata may already identify the server @@ -227,6 +221,17 @@ auto attach_server_info(const MCPProtocolVersion version, } } +auto attach_server_info(const MCPProtocolVersion version, + sourcemeta::core::JSON &result, + const std::optional &server_info) + -> void { + if (!server_info.has_value() || !mcp_requires_result_type(version)) { + return; + } + attach_server_info(result, + internal::make_implementation(version, *server_info)); +} + auto decorate_result( const MCPProtocolVersion version, sourcemeta::core::JSON &result, const std::optional &server_info = std::nullopt) @@ -256,12 +261,20 @@ auto decorate_result( "or extension results"); } + auto info{ + server_info.has_value() + ? std::optional{internal::make_implementation( + version, *server_info)} + : std::nullopt}; + if (result.try_at("resultType", MCP_HASH_RESULT_TYPE) == nullptr) { result.assign_assume_new("resultType", sourcemeta::core::JSON{"complete"}, MCP_HASH_RESULT_TYPE); } - attach_server_info(version, result, server_info); + if (info) { + attach_server_info(result, std::move(*info)); + } } } // namespace @@ -1066,11 +1079,11 @@ auto mcp_make_completion_result(const MCPProtocolVersion version, JSON values, return result; } -auto mcp_write_result(std::ostream &stream, const MCPProtocolVersion version, - const JSON::StringView method, const JSON &identifier, - const JSON &result, - const std::optional cache_policy, - const std::optional server_info) +namespace { +auto validate_write_result(const MCPProtocolVersion version, + const JSON::StringView method, + const JSON &identifier, const JSON &result, + const std::optional &cache_policy) -> void { internal::require(internal::valid_id(identifier), "Invalid MCP identifier"); internal::require(mcp_is_request_method(version, method) && @@ -1102,6 +1115,10 @@ auto mcp_write_result(std::ostream &stream, const MCPProtocolVersion version, internal::require(cache_policy.has_value(), "Cacheable results require a policy"); } + if (cache_policy) { + internal::require(cache_policy->ttl_ms >= 0, + "A cache time to live cannot be negative"); + } const JSON *entries = nullptr; if (method == MCP_METHOD_TOOLS_LIST) { entries = result.try_at("tools", sourcemeta::core::MCP_HASH_TOOLS); @@ -1164,11 +1181,46 @@ auto mcp_write_result(std::ostream &stream, const MCPProtocolVersion version, cursor) { internal::require(cursor->is_string(), "Invalid result cursor"); } - auto payload{result}; - decorate_result(version, payload, server_info); +} + +auto write_result_impl(std::ostream &stream, const MCPProtocolVersion version, + const JSON::StringView method, const JSON &identifier, + JSON &&result, + const std::optional &cache_policy, + const std::optional &server_info) + -> void { + // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) + const auto envelope_identifier{identifier}; + const JSON::String operation{method}; + decorate_result(version, result, server_info); if (cache_policy) { - decorate_cacheable_result(version, payload, *cache_policy, method); + decorate_cacheable_result(version, result, *cache_policy, operation); } - stringify(jsonrpc_make_success(identifier, std::move(payload)), stream); + stringify(jsonrpc_make_success(envelope_identifier, std::move(result)), + stream); +} +} // namespace + +auto mcp_write_result(std::ostream &stream, const MCPProtocolVersion version, + const JSON::StringView method, const JSON &identifier, + JSON &&result, + const std::optional cache_policy, + const std::optional server_info) + -> void { + validate_write_result(version, method, identifier, result, cache_policy); + write_result_impl(stream, version, method, identifier, std::move(result), + cache_policy, server_info); +} + +auto mcp_write_result(std::ostream &stream, const MCPProtocolVersion version, + const JSON::StringView method, const JSON &identifier, + const JSON &result, + const std::optional cache_policy, + const std::optional server_info) + -> void { + validate_write_result(version, method, identifier, result, cache_policy); + auto payload{result}; + write_result_impl(stream, version, method, identifier, std::move(payload), + cache_policy, server_info); } } // namespace sourcemeta::core diff --git a/vendor/core/src/core/mcp/validation.h b/vendor/core/src/core/mcp/validation.h index cb6461bb4..1bba501eb 100644 --- a/vendor/core/src/core/mcp/validation.h +++ b/vendor/core/src/core/mcp/validation.h @@ -11,7 +11,6 @@ #include #include // std::all_of -#include // std::isfinite #include // std::initializer_list #include // std::set #include // std::move, std::pair @@ -166,12 +165,6 @@ inline auto icon_size(const JSON::StringView value) -> bool { }); } -inline auto strings(const JSON &value) -> bool { - return value.is_array() && - std::all_of(value.as_array().begin(), value.as_array().end(), - [](const auto &item) { return item.is_string(); }); -} - inline auto annotations(const JSON &value, const bool received = false) -> bool { const auto *item{ @@ -189,19 +182,18 @@ inline auto annotations(const JSON &value, const bool received = false) if (const auto *priority{ field(*item, "priority", sourcemeta::core::MCP_HASH_PRIORITY)}; priority != nullptr && - (!priority->is_number() || - (priority->is_real() && !std::isfinite(priority->to_real())) || - *priority < JSON{0} || *priority > JSON{1})) { + (!priority->is_number() || *priority < JSON{0} || *priority > JSON{1})) { return false; } if (const auto *audience{ field(*item, "audience", sourcemeta::core::MCP_HASH_AUDIENCE)}; audience != nullptr) { - if (!strings(*audience)) { + if (!audience->is_array_of_strings()) { return false; } for (const auto &role : audience->as_array()) { - if (role.to_string() != "user" && role.to_string() != "assistant") { + const auto &role_name{role.to_string()}; + if (role_name != "user" && role_name != "assistant") { return false; } } @@ -231,7 +223,7 @@ inline auto icons(const JSON &value, const bool received = false) -> bool { if (const auto *sizes{ field(item, "sizes", sourcemeta::core::MCP_HASH_SIZES)}; sizes != nullptr) { - if (!strings(*sizes)) { + if (!sizes->is_array_of_strings()) { return false; } @@ -243,10 +235,14 @@ inline auto icons(const JSON &value, const bool received = false) -> bool { } if (const auto *theme{ field(item, "theme", sourcemeta::core::MCP_HASH_THEME)}; - (theme != nullptr) && - (!theme->is_string() || - (theme->to_string() != "light" && theme->to_string() != "dark"))) { - return false; + theme != nullptr) { + if (!theme->is_string()) { + return false; + } + const auto &theme_name{theme->to_string()}; + if (theme_name != "light" && theme_name != "dark") { + return false; + } } } return true; @@ -317,7 +313,7 @@ inline auto metadata_key(const JSON::StringView key, const bool prefix_required) const auto slash{key.find('/')}; JSON::StringView name{key}; if (slash == JSON::StringView::npos) { - if (prefix_required) { + if (prefix_required || key.empty()) { return false; } } else { @@ -364,7 +360,7 @@ inline auto sampling_block(const JSON &value, const bool received = false) value)) { return false; } - const auto name{type->to_string()}; + const auto &name{type->to_string()}; if (name == "text" || name == "image" || name == "audio") { return sourcemeta::core::internal::valid_content( MCPProtocolVersion::V_2026_07_28, value, received); @@ -405,7 +401,7 @@ inline auto sampling_message_block(const JSON &block, const bool tools, if (!sampling_block(block)) { return false; } - const auto type{ + const auto &type{ block.at("type", sourcemeta::core::MCP_HASH_TYPE).to_string()}; if (type == "tool_result") { return tools && answering && role == "user" && @@ -487,7 +483,7 @@ inline auto sampling_options(const JSON ¶ms) -> bool { } if (const auto *stop{field(params, "stopSequences", sourcemeta::core::MCP_HASH_STOP_SEQUENCES)}; - (stop != nullptr) && !strings(*stop)) { + (stop != nullptr) && !stop->is_array_of_strings()) { return false; } if (const auto *choice{ @@ -917,7 +913,7 @@ inline auto valid_resource(const MCPProtocolVersion version, const JSON &value, validation::field(value, "size", sourcemeta::core::MCP_HASH_SIZE)}; return validation::base(value, received) && validation::annotations(value, received) && - ((size == nullptr) || (size->is_integral() && *size >= JSON{0})); + ((size == nullptr) || (size->is_integral() && size->is_positive())); } inline auto valid_content(const MCPProtocolVersion version, const JSON &value, @@ -931,7 +927,7 @@ inline auto valid_content(const MCPProtocolVersion version, const JSON &value, if ((type == nullptr) || !type->is_string()) { return false; } - const auto name{type->to_string()}; + const auto &name{type->to_string()}; if (name == "text") { return validation::string_field(value, "text", sourcemeta::core::MCP_HASH_TEXT, true); @@ -1005,7 +1001,7 @@ inline auto valid_input_requests(const JSON &value, !valid_meta(MCPProtocolVersion::V_2026_07_28, *params))) { return false; } - const auto name{method->to_string()}; + const auto &name{method->to_string()}; if (name == MCP_METHOD_ROOTS_LIST) { if (!capabilities.roots) { return false; @@ -1149,11 +1145,8 @@ inline auto valid_input_response(const JSON::StringView method, return false; } for (const auto &entry : content->as_object()) { - if (entry.second.is_real() && !std::isfinite(entry.second.to_real())) { - return false; - } if (!entry.second.is_string() && !entry.second.is_number() && - !entry.second.is_boolean() && !validation::strings(entry.second)) { + !entry.second.is_boolean() && !entry.second.is_array_of_strings()) { return false; } } diff --git a/vendor/core/src/core/oidc/oidc_authentication.cc b/vendor/core/src/core/oidc/oidc_authentication.cc index 93ff58afd..9519ba1a6 100644 --- a/vendor/core/src/core/oidc/oidc_authentication.cc +++ b/vendor/core/src/core/oidc/oidc_authentication.cc @@ -5,6 +5,7 @@ #include #include // std::array +#include // assert #include // std::size_t #include // std::less #include // std::optional, std::nullopt @@ -81,10 +82,10 @@ auto drop_offline_access(std::string_view &scope, std::string &storage) if (in_arena) { offset = static_cast(scope.data() - arena); } else { - if (storage.capacity() - storage.size() < scope.size()) { - return; - } - + // The parser reserved the whole query up front and a borrowed value took + // none of that room, while everything decoded into the arena is at most as + // long as the query it came from, so what is appended here always fits + assert(storage.capacity() - storage.size() >= scope.size()); offset = storage.size(); storage.resize(storage.size() + scope.size()); } diff --git a/vendor/core/src/core/oidc/oidc_id_token.cc b/vendor/core/src/core/oidc/oidc_id_token.cc index 1640202e0..01a18db5d 100644 --- a/vendor/core/src/core/oidc/oidc_id_token.cc +++ b/vendor/core/src/core/oidc/oidc_id_token.cc @@ -170,10 +170,11 @@ auto oidc_id_token_checks(const JWT &token, const std::string_view issuer, std::optional authentication_time; const auto *auth_time{payload.try_at("auth_time"sv, HASH_AUTH_TIME)}; if (auth_time != nullptr && auth_time->is_number()) { - // A NumericDate may be non-integer (RFC 7519 Section 2), and a value beyond - // the range of a double cannot stand for a usable timestamp, so it is - // treated as absent rather than aborting, matching how the JWT layer reads - // the registered time claims + // A NumericDate may be non-integer (RFC 7519 Section 2). A value past what + // a double stands for refuses to be read as one at all, and one the clock + // cannot stand for comes back as no time, so either way the claim reads as + // absent rather than aborting, matching how the JWT layer reads the + // registered time claims try { authentication_time = from_unix_timestamp( std::chrono::duration{auth_time->as_real()}); diff --git a/vendor/core/src/core/punycode/include/sourcemeta/core/punycode.h b/vendor/core/src/core/punycode/include/sourcemeta/core/punycode.h index b996e60e8..d6169e16f 100644 --- a/vendor/core/src/core/punycode/include/sourcemeta/core/punycode.h +++ b/vendor/core/src/core/punycode/include/sourcemeta/core/punycode.h @@ -9,7 +9,10 @@ #include // NOLINTEND(misc-include-cleaner) +#include // std::size_t +#include // std::uint32_t #include // std::istream +#include // std::numeric_limits #include // std::ostream #include // std::string, std::u32string #include // std::string_view, std::u32string_view @@ -27,6 +30,21 @@ namespace sourcemeta::core { // See https://www.rfc-editor.org/rfc/rfc3492 +/// @ingroup punycode +/// The most code points an encode accepts when a caller names no bound of its +/// own. RFC 3492 Section 6.4 offers bounding the input as one way of keeping +/// the position counters from wrapping, which is the ceiling this stands at, so +/// a caller may name a smaller bound but never a larger one. +inline constexpr std::size_t PUNYCODE_MAXIMUM_CODE_POINTS{ + std::numeric_limits::max()}; + +/// @ingroup punycode +/// The most bytes a decode accepts when a caller names no bound of its own, +/// which stands at the same ceiling the encode bound does and may likewise only +/// be tightened. +inline constexpr std::size_t PUNYCODE_MAXIMUM_ENCODED_BYTES{ + std::numeric_limits::max()}; + /// @ingroup punycode /// Encode Unicode code points (UTF-32) to Punycode. For example: /// @@ -45,8 +63,12 @@ namespace sourcemeta::core { /// because the C++ standard library does not define the required locale facets /// (`std::ctype`) for `std::basic_istream` and /// `std::basic_ostream` to function properly. +/// +/// A bound smaller than the default refuses a larger input. SOURCEMETA_CORE_PUNYCODE_EXPORT -auto utf32_to_punycode(std::u32string_view input) -> std::string; +auto utf32_to_punycode(std::u32string_view input, + std::size_t maximum_code_points = + PUNYCODE_MAXIMUM_CODE_POINTS) -> std::string; /// @ingroup punycode /// Encode UTF-8 to Punycode using streams. For example: @@ -61,8 +83,12 @@ auto utf32_to_punycode(std::u32string_view input) -> std::string; /// sourcemeta::core::utf8_to_punycode(input, output); /// assert(output.str() == "Mnchen-3ya"); /// ``` +/// +/// A bound smaller than the default refuses a larger input. SOURCEMETA_CORE_PUNYCODE_EXPORT -auto utf8_to_punycode(std::istream &input, std::ostream &output) -> void; +auto utf8_to_punycode( + std::istream &input, std::ostream &output, + std::size_t maximum_code_points = PUNYCODE_MAXIMUM_CODE_POINTS) -> void; /// @ingroup punycode /// Encode UTF-8 to Punycode. For example: @@ -74,8 +100,12 @@ auto utf8_to_punycode(std::istream &input, std::ostream &output) -> void; /// assert(sourcemeta::core::utf8_to_punycode("M\xC3\xBCnchen") == /// "Mnchen-3ya"); /// ``` +/// +/// A bound smaller than the default refuses a larger input. SOURCEMETA_CORE_PUNYCODE_EXPORT -auto utf8_to_punycode(const std::string_view input) -> std::string; +auto utf8_to_punycode(const std::string_view input, + std::size_t maximum_code_points = + PUNYCODE_MAXIMUM_CODE_POINTS) -> std::string; /// @ingroup punycode /// Decode Punycode to Unicode code points (UTF-32). For example: @@ -96,8 +126,12 @@ auto utf8_to_punycode(const std::string_view input) -> std::string; /// because the C++ standard library does not define the required locale facets /// (`std::ctype`) for `std::basic_istream` and /// `std::basic_ostream` to function properly. +/// +/// A bound smaller than the default refuses a larger input. SOURCEMETA_CORE_PUNYCODE_EXPORT -auto punycode_to_utf32(const std::string_view input) -> std::u32string; +auto punycode_to_utf32(const std::string_view input, + std::size_t maximum_encoded_bytes = + PUNYCODE_MAXIMUM_ENCODED_BYTES) -> std::u32string; /// @ingroup punycode /// Decode Punycode to UTF-8 using streams. For example: @@ -112,8 +146,12 @@ auto punycode_to_utf32(const std::string_view input) -> std::u32string; /// sourcemeta::core::punycode_to_utf8(input, output); /// assert(output.str() == "M\xC3\xBCnchen"); /// ``` +/// +/// A bound smaller than the default refuses a larger input. SOURCEMETA_CORE_PUNYCODE_EXPORT -auto punycode_to_utf8(std::istream &input, std::ostream &output) -> void; +auto punycode_to_utf8( + std::istream &input, std::ostream &output, + std::size_t maximum_encoded_bytes = PUNYCODE_MAXIMUM_ENCODED_BYTES) -> void; /// @ingroup punycode /// Decode Punycode to UTF-8. For example: @@ -125,8 +163,12 @@ auto punycode_to_utf8(std::istream &input, std::ostream &output) -> void; /// assert(sourcemeta::core::punycode_to_utf8("Mnchen-3ya") == /// "M\xC3\xBCnchen"); /// ``` +/// +/// A bound smaller than the default refuses a larger input. SOURCEMETA_CORE_PUNYCODE_EXPORT -auto punycode_to_utf8(const std::string_view input) -> std::string; +auto punycode_to_utf8(const std::string_view input, + std::size_t maximum_encoded_bytes = + PUNYCODE_MAXIMUM_ENCODED_BYTES) -> std::string; } // namespace sourcemeta::core diff --git a/vendor/core/src/core/punycode/punycode.cc b/vendor/core/src/core/punycode/punycode.cc index 63059eb4d..2723fab75 100644 --- a/vendor/core/src/core/punycode/punycode.cc +++ b/vendor/core/src/core/punycode/punycode.cc @@ -2,8 +2,9 @@ #include #include -#include // std::ranges::sort +#include // std::min, std::ranges::sort #include // assert +#include // std::size_t #include // std::uint32_t, std::uint64_t #include // std::numeric_limits #include // std::vector @@ -82,11 +83,14 @@ static constexpr auto is_basic(const char32_t code_point) -> bool { } static auto punycode_encode(const std::u32string_view codepoints, - std::string &output) -> void { + std::string &output, + const std::size_t maximum_code_points) -> void { // RFC 3492 Section 6.4 offers bounding the input as one way of keeping the // counters from wrapping, alongside the detection the arithmetic below - // carries out, so this bound is a choice made here rather than a requirement - if (codepoints.size() > std::numeric_limits::max()) { + // carries out. What a caller names only ever tightens the ceiling the + // counters stand at, as a wider input than that has nowhere to be addressed + if (codepoints.size() > + std::min(maximum_code_points, PUNYCODE_MAXIMUM_CODE_POINTS)) { throw PunycodeError("Input is too large"); } @@ -181,12 +185,14 @@ static auto punycode_encode(const std::u32string_view codepoints, } static auto punycode_decode(const std::string_view encoded, - std::u32string &decoded) -> void { + std::u32string &decoded, + const std::size_t maximum_encoded_bytes) -> void { // RFC 3492 Section 6.4 offers bounding the input as one way of keeping the // position counter from wrapping, alongside the detection the arithmetic - // below carries out, so this bound is a choice made here rather than a - // requirement - if (encoded.size() > std::numeric_limits::max()) { + // below carries out. What a caller names only ever tightens the ceiling the + // counter stands at, as a wider input than that has nowhere to be addressed + if (encoded.size() > + std::min(maximum_encoded_bytes, PUNYCODE_MAXIMUM_ENCODED_BYTES)) { throw PunycodeError("Input is too large"); } @@ -283,57 +289,71 @@ static auto punycode_decode(const std::string_view encoded, } } -auto utf32_to_punycode(std::u32string_view input) -> std::string { +auto utf32_to_punycode(std::u32string_view input, + const std::size_t maximum_code_points) -> std::string { std::string result; - punycode_encode(input, result); + punycode_encode(input, result, maximum_code_points); return result; } -auto punycode_to_utf32(const std::string_view input) -> std::u32string { +auto punycode_to_utf32(const std::string_view input, + const std::size_t maximum_encoded_bytes) + -> std::u32string { std::u32string result; - punycode_decode(input, result); + punycode_decode(input, result, maximum_encoded_bytes); return result; } -auto utf8_to_punycode(std::istream &input, std::ostream &output) -> void { +auto utf8_to_punycode(std::istream &input, std::ostream &output, + const std::size_t maximum_code_points) -> void { const auto codepoints = utf8_to_utf32(input); if (!codepoints.has_value()) { throw PunycodeError("Invalid UTF-8 input"); } std::string result; - punycode_encode(codepoints.value(), result); + punycode_encode(codepoints.value(), result, maximum_code_points); output << result; } -auto punycode_to_utf8(std::istream &input, std::ostream &output) -> void { +auto punycode_to_utf8(std::istream &input, std::ostream &output, + const std::size_t maximum_encoded_bytes) -> void { + // The bound is held to while the stream is read rather than once it has all + // arrived, so that what a caller refuses is never taken in to begin with + const auto bound{ + std::min(maximum_encoded_bytes, PUNYCODE_MAXIMUM_ENCODED_BYTES)}; std::string encoded; char character{0}; while (input.get(character)) { encoded.push_back(character); + if (encoded.size() > bound) { + throw PunycodeError("Input is too large"); + } } std::u32string decoded; - punycode_decode(encoded, decoded); + punycode_decode(encoded, decoded, maximum_encoded_bytes); for (const auto code_point : decoded) { codepoint_to_utf8(code_point, output); } } -auto utf8_to_punycode(const std::string_view input) -> std::string { +auto utf8_to_punycode(const std::string_view input, + const std::size_t maximum_code_points) -> std::string { const auto codepoints = utf8_to_utf32(input); if (!codepoints.has_value()) { throw PunycodeError("Invalid UTF-8 input"); } std::string result; - punycode_encode(codepoints.value(), result); + punycode_encode(codepoints.value(), result, maximum_code_points); return result; } -auto punycode_to_utf8(const std::string_view input) -> std::string { +auto punycode_to_utf8(const std::string_view input, + const std::size_t maximum_encoded_bytes) -> std::string { std::u32string decoded; - punycode_decode(input, decoded); + punycode_decode(input, decoded, maximum_encoded_bytes); std::string output; output.reserve(decoded.size()); for (const auto code_point : decoded) { diff --git a/vendor/core/src/core/regex/permissive.h b/vendor/core/src/core/regex/permissive.h index fe3515357..ecadb823f 100644 --- a/vendor/core/src/core/regex/permissive.h +++ b/vendor/core/src/core/regex/permissive.h @@ -10,7 +10,7 @@ #include // std::optional #include // std::string #include // std::string_view -#include // std::move, std::pair, std::unreachable +#include // std::move, std::pair namespace sourcemeta::core { @@ -111,30 +111,21 @@ constexpr auto NON_DIGIT_CLASS{(~DIGIT_CLASS).reset(0)}; constexpr auto NON_WORD_CLASS{(~WORD_CLASS).reset(0)}; constexpr auto NON_SPACE_CLASS{(~SPACE_CLASS).reset(0)}; +// Each shorthand names a class in its lower case and the complement of that +// class in its upper case, so which class is meant and whether it is negated +// are read apart rather than spelled out once per pairing. The caller matches +// the shorthand against the set of them before asking, which is what leaves +// the last pairing to answer for whatever is not one of the other two inline auto set_shorthand_class(std::bitset<128> &characters, const char shorthand) -> void { - switch (shorthand) { - case 'd': - characters |= DIGIT_CLASS; - return; - case 'D': - characters |= NON_DIGIT_CLASS; - return; - case 'w': - characters |= WORD_CLASS; - return; - case 'W': - characters |= NON_WORD_CLASS; - return; - case 's': - characters |= SPACE_CLASS; - return; - case 'S': - characters |= NON_SPACE_CLASS; - return; - default: - // The caller matches the shorthand against the set of them before asking - std::unreachable(); + const auto lowered{static_cast(shorthand | 0x20)}; + const auto negated{shorthand != lowered}; + if (lowered == 'd') { + characters |= negated ? NON_DIGIT_CLASS : DIGIT_CLASS; + } else if (lowered == 'w') { + characters |= negated ? NON_WORD_CLASS : WORD_CLASS; + } else { + characters |= negated ? NON_SPACE_CLASS : SPACE_CLASS; } } diff --git a/vendor/core/src/core/regex/regex.cc b/vendor/core/src/core/regex/regex.cc index 5b8835ae0..9f604e8f4 100644 --- a/vendor/core/src/core/regex/regex.cc +++ b/vendor/core/src/core/regex/regex.cc @@ -38,6 +38,32 @@ auto compile_pcre2(const std::string &pattern, const std::uint32_t options) return RegexTypePCRE2{std::shared_ptr(pcre2_regex)}; } +auto matches_range(const RegexTypeRange &range, const std::string_view value) + -> bool { + // ECMA-262 "." matches a single code point, not a single byte, so the + // bounds are compared against the number of code points + return utf8_codepoint_within(value, range.first, range.second); +} + +auto matches_pcre2(const RegexTypePCRE2 ®ex, const std::string_view value) + -> bool { + auto *pcre2_code_ptr{static_cast(regex.code.get())}; + // Allocated once per thread and reused across calls to avoid + // allocating every time. It is intentionally never freed, as + // releasing it on thread exit would make matching unsafe during the + // destruction of other objects with thread storage duration + thread_local pcre2_match_data *match_data{ + pcre2_match_data_create(1, nullptr)}; + // A null context selects the built-in default limits, which guarantee + // that pathological patterns applied to adversarial inputs terminate. + // Note that exhausting any matching resource, like the machine stack + // of the just-in-time fast path on long values, counts as a failure + const int match_result{ + pcre2_match(pcre2_code_ptr, reinterpret_cast(value.data()), + value.size(), 0, PCRE2_NO_UTF_CHECK, match_data, nullptr)}; + return match_result >= 0; +} + } // namespace auto to_regex(const std::string_view pattern, const RegexDialect dialect, @@ -131,30 +157,10 @@ auto matches(const Regex ®ex, const std::string_view value) -> bool { return value.starts_with(*std::get_if(®ex)); case RegexIndex::NonEmpty: return !value.empty(); - case RegexIndex::Range: { - // ECMA-262 "." matches a single code point, not a single byte, so the - // bounds are compared against the number of code points - const RegexTypeRange *range{std::get_if(®ex)}; - return utf8_codepoint_within(value, range->first, range->second); - } - case RegexIndex::PCRE2: { - const RegexTypePCRE2 *pcre2_regex{std::get_if(®ex)}; - auto *pcre2_code_ptr{static_cast(pcre2_regex->code.get())}; - // Allocated once per thread and reused across calls to avoid - // allocating every time. It is intentionally never freed, as - // releasing it on thread exit would make matching unsafe during the - // destruction of other objects with thread storage duration - thread_local pcre2_match_data *match_data{ - pcre2_match_data_create(1, nullptr)}; - // A null context selects the built-in default limits, which guarantee - // that pathological patterns applied to adversarial inputs terminate. - // Note that exhausting any matching resource, like the machine stack - // of the just-in-time fast path on long values, counts as a failure - const int match_result{pcre2_match( - pcre2_code_ptr, reinterpret_cast(value.data()), - value.size(), 0, PCRE2_NO_UTF_CHECK, match_data, nullptr)}; - return match_result >= 0; - } + case RegexIndex::Range: + return matches_range(*std::get_if(®ex), value); + case RegexIndex::PCRE2: + return matches_pcre2(*std::get_if(®ex), value); case RegexIndex::Noop: return true; } diff --git a/vendor/core/src/core/semver/semver.cc b/vendor/core/src/core/semver/semver.cc index 373e1ddc3..1dc3cb019 100644 --- a/vendor/core/src/core/semver/semver.cc +++ b/vendor/core/src/core/semver/semver.cc @@ -367,15 +367,15 @@ auto parse_semver(const std::string_view input, std::uint64_t &major, } } - if (position != input.size()) { - if constexpr (ShouldThrow) { - throw sourcemeta::core::SemVerParseError(position + 1); - } else { - return false; - } + if (position == input.size()) { + return true; } - return true; + if constexpr (ShouldThrow) { + throw sourcemeta::core::SemVerParseError(position + 1); + } else { + return false; + } } } // namespace diff --git a/vendor/core/src/core/terminal/terminal.cc b/vendor/core/src/core/terminal/terminal.cc index 5d633b5bc..3d55b6efa 100644 --- a/vendor/core/src/core/terminal/terminal.cc +++ b/vendor/core/src/core/terminal/terminal.cc @@ -70,9 +70,13 @@ auto terminal_color_enabled(TerminalStream stream) noexcept -> bool { return true; case TerminalColorPolicy::Disabled: return false; - default: - std::unreachable(); } + + // Clang settles that no other value arrives, so only GCC and MSVC + // need to be told that the end of this function is never reached +#if !defined(__clang__) + std::unreachable(); +#endif } auto terminal_sgr_reset() noexcept -> std::string_view { diff --git a/vendor/core/src/core/time/asctime.cc b/vendor/core/src/core/time/asctime.cc index acc0452c8..ce1eb18c5 100644 --- a/vendor/core/src/core/time/asctime.cc +++ b/vendor/core/src/core/time/asctime.cc @@ -35,8 +35,8 @@ auto to_asctime(const std::chrono::system_clock::time_point time) return stream.str(); } -auto from_asctime(const std::string_view value) noexcept - -> std::optional try { +auto from_asctime(const std::string_view value) + -> std::optional { if (value.size() != 24) { return std::nullopt; } @@ -79,8 +79,6 @@ auto from_asctime(const std::string_view value) noexcept return std::nullopt; } return broken_down_time_to_time_point(parts); -} catch (...) { - return std::nullopt; } } // namespace sourcemeta::core diff --git a/vendor/core/src/core/time/imf_fixdate.cc b/vendor/core/src/core/time/imf_fixdate.cc index 73470b0a4..0bffefc8b 100644 --- a/vendor/core/src/core/time/imf_fixdate.cc +++ b/vendor/core/src/core/time/imf_fixdate.cc @@ -33,8 +33,8 @@ auto to_imf_fixdate(const std::chrono::system_clock::time_point time) return stream.str(); } -auto from_imf_fixdate(const std::string_view value) noexcept - -> std::optional try { +auto from_imf_fixdate(const std::string_view value) + -> std::optional { if (value.size() != 29) { return std::nullopt; } @@ -73,8 +73,6 @@ auto from_imf_fixdate(const std::string_view value) noexcept return std::nullopt; } return broken_down_time_to_time_point(parts); -} catch (...) { - return std::nullopt; } } // namespace sourcemeta::core diff --git a/vendor/core/src/core/time/include/sourcemeta/core/time.h b/vendor/core/src/core/time/include/sourcemeta/core/time.h index 6ca16831e..e875f951e 100644 --- a/vendor/core/src/core/time/include/sourcemeta/core/time.h +++ b/vendor/core/src/core/time/include/sourcemeta/core/time.h @@ -57,7 +57,7 @@ auto to_imf_fixdate(const std::chrono::system_clock::time_point time) /// assert(point.has_value()); /// ``` SOURCEMETA_CORE_TIME_EXPORT -auto from_imf_fixdate(const std::string_view value) noexcept +auto from_imf_fixdate(const std::string_view value) -> std::optional; /// @ingroup time @@ -93,7 +93,7 @@ auto to_rfc850_date(const std::chrono::system_clock::time_point time) /// assert(point.has_value()); /// ``` SOURCEMETA_CORE_TIME_EXPORT -auto from_rfc850_date(const std::string_view value) noexcept +auto from_rfc850_date(const std::string_view value) -> std::optional; /// @ingroup time @@ -130,7 +130,7 @@ auto to_asctime(const std::chrono::system_clock::time_point time) /// assert(point.has_value()); /// ``` SOURCEMETA_CORE_TIME_EXPORT -auto from_asctime(const std::string_view value) noexcept +auto from_asctime(const std::string_view value) -> std::optional; /// @ingroup time diff --git a/vendor/core/src/core/time/rfc850_date.cc b/vendor/core/src/core/time/rfc850_date.cc index bcf4e12cd..6ce10e0f5 100644 --- a/vendor/core/src/core/time/rfc850_date.cc +++ b/vendor/core/src/core/time/rfc850_date.cc @@ -41,8 +41,8 @@ auto to_rfc850_date(const std::chrono::system_clock::time_point time) return stream.str(); } -auto from_rfc850_date(const std::string_view value) noexcept - -> std::optional try { +auto from_rfc850_date(const std::string_view value) + -> std::optional { const auto comma_position{value.find(',')}; if (comma_position == std::string_view::npos) { return std::nullopt; @@ -99,8 +99,6 @@ auto from_rfc850_date(const std::string_view value) noexcept return std::nullopt; } return broken_down_time_to_time_point(parts); -} catch (...) { - return std::nullopt; } } // namespace sourcemeta::core diff --git a/vendor/core/src/core/uri/parse.cc b/vendor/core/src/core/uri/parse.cc index 2a5a2c912..f98fb5629 100644 --- a/vendor/core/src/core/uri/parse.cc +++ b/vendor/core/src/core/uri/parse.cc @@ -81,17 +81,43 @@ auto accept_iri_extension(const std::string_view input, } } +// Every reader below turns down what it was handed in the same two ways, +// depending on whether it was asked to check the input or to take it apart, so +// what a refusal answers with is spelled out once here +template +auto parse_refused() + -> std::conditional_t> { + if constexpr (CheckOnly) { + return false; + } else { + return std::nullopt; + } +} + +// A reader that has found what it was after answers with the text it took or +// with the bare fact that it was there, and steps past the delimiter either +// way, so what being taken looks like is spelled out once here +template +auto parse_taken(const std::string_view input, + const std::string_view::size_type start, + std::string_view::size_type &position) + -> std::conditional_t> { + const auto taken{input.substr(start, position - start)}; + position += 1; + if constexpr (CheckOnly) { + return true; + } else { + return std::string{taken}; + } +} + template auto parse_scheme(const std::string_view input, std::string_view::size_type &position) -> std::conditional_t> { if (position >= input.size() || !std::isalpha(static_cast(input[position]))) { - if constexpr (CheckOnly) { - return false; - } else { - return std::nullopt; - } + return parse_refused(); } const auto start = position; @@ -102,22 +128,11 @@ auto parse_scheme(const std::string_view input, } if (position < input.size() && input[position] == URI_COLON) { - if constexpr (CheckOnly) { - position += 1; - return true; - } else { - std::string scheme{input.substr(start, position - start)}; - position += 1; - return scheme; - } + return parse_taken(input, start, position); } position = start; - if constexpr (CheckOnly) { - return false; - } else { - return std::nullopt; - } + return parse_refused(); } template @@ -126,11 +141,7 @@ auto parse_port(const std::string_view input, -> std::conditional_t> { if (position >= input.size() || !std::isdigit(static_cast(input[position]))) { - if constexpr (CheckOnly) { - return false; - } else { - return std::nullopt; - } + return parse_refused(); } const auto start = position; @@ -289,12 +300,7 @@ auto parse_host(const std::string_view input, if (input[position] == URI_OPEN_BRACKET) { ip_literal = true; - if constexpr (CheckOnly) { - parse_ipv6(input, position); - return; - } else { - return parse_ipv6(input, position); - } + return parse_ipv6(input, position); } const auto start = position; @@ -364,11 +370,7 @@ auto parse_userinfo(const std::string_view input, } position = start; - if constexpr (CheckOnly) { - return false; - } else { - return std::nullopt; - } + return parse_refused(); } template @@ -376,20 +378,12 @@ auto parse_path(const std::string_view input, std::string_view::size_type &position) -> std::conditional_t> { if (position >= input.size()) { - if constexpr (CheckOnly) { - return false; - } else { - return std::nullopt; - } + return parse_refused(); } const auto first_char = input[position]; if (first_char == URI_QUESTION || first_char == URI_HASH) { - if constexpr (CheckOnly) { - return false; - } else { - return std::nullopt; - } + return parse_refused(); } const auto start = position; @@ -422,11 +416,7 @@ auto parse_query(const std::string_view input, std::string_view::size_type &position) -> std::conditional_t> { if (position >= input.size() || input[position] != URI_QUESTION) { - if constexpr (CheckOnly) { - return false; - } else { - return std::nullopt; - } + return parse_refused(); } position += 1; @@ -462,11 +452,7 @@ auto parse_fragment(const std::string_view input, std::string_view::size_type &position) -> std::conditional_t> { if (position >= input.size() || input[position] != URI_HASH) { - if constexpr (CheckOnly) { - return false; - } else { - return std::nullopt; - } + return parse_refused(); } position += 1; diff --git a/vendor/core/src/core/uri/setters.cc b/vendor/core/src/core/uri/setters.cc index 7f77e4097..c04348a0e 100644 --- a/vendor/core/src/core/uri/setters.cc +++ b/vendor/core/src/core/uri/setters.cc @@ -81,6 +81,18 @@ auto validate_raw_path(const std::string_view path) -> void { namespace sourcemeta::core { +namespace { + +// A path hangs off a root when what it is set on names one, which a scheme +// that addresses hierarchically does, and which an authority does on its own +auto needs_root_slash(const URI &uri) -> bool { + const auto is_hierarchical{!uri.is_urn() && !uri.is_tag() && + !uri.is_mailto() && uri.scheme().has_value()}; + return is_hierarchical || uri.host().has_value(); +} + +} // namespace + auto URI::path(const std::string &path) -> URI & { if (path.empty()) { this->path_ = std::nullopt; @@ -93,12 +105,7 @@ auto URI::path(const std::string &path) -> URI & { validate_raw_path(path); - // Determine if this URI needs a leading slash - // (URIs with scheme/authority need leading slash, except URNs/tags/mailto) - const auto needs_leading_slash = - (!this->is_urn() && !this->is_tag() && !this->is_mailto() && - this->scheme_.has_value()) || - this->host_.has_value(); + const auto needs_leading_slash{needs_root_slash(*this)}; this->path_ = apply_leading_slash_transform(std::optional{path}, needs_leading_slash); @@ -117,12 +124,7 @@ auto URI::path(std::string &&path) -> URI & { validate_raw_path(path); - // Determine if this URI needs a leading slash - // (URIs with scheme/authority need leading slash, except URNs/tags/mailto) - const auto needs_leading_slash = - (!this->is_urn() && !this->is_tag() && !this->is_mailto() && - this->scheme_.has_value()) || - this->host_.has_value(); + const auto needs_leading_slash{needs_root_slash(*this)}; this->path_ = apply_leading_slash_transform( std::optional{std::move(path)}, needs_leading_slash); @@ -224,10 +226,7 @@ auto URI::append_path(std::string_view path) -> URI & { "Cannot append a URI as a path that contains an invalid character"}; } - const auto needs_leading_slash = - (!this->is_urn() && !this->is_tag() && !this->is_mailto() && - this->scheme_.has_value()) || - this->host_.has_value(); + const auto needs_leading_slash{needs_root_slash(*this)}; merge_reference_path(this->path_, needs_leading_slash, path); return *this; } @@ -256,10 +255,7 @@ auto URI::append_path(const URI &reference) -> URI & { return *this; } - const auto needs_leading_slash = - (!this->is_urn() && !this->is_tag() && !this->is_mailto() && - this->scheme_.has_value()) || - this->host_.has_value(); + const auto needs_leading_slash{needs_root_slash(*this)}; merge_reference_path(this->path_, needs_leading_slash, reference.path_.value()); return *this; @@ -272,10 +268,7 @@ auto URI::append_path(URI &&reference) -> URI & { return *this; } - const auto needs_leading_slash = - (!this->is_urn() && !this->is_tag() && !this->is_mailto() && - this->scheme_.has_value()) || - this->host_.has_value(); + const auto needs_leading_slash{needs_root_slash(*this)}; std::string reference_path{std::move(reference.path_.value())}; reference.path_ = std::nullopt; merge_reference_path(this->path_, needs_leading_slash, reference_path); diff --git a/vendor/core/src/core/uritemplate/helpers.h b/vendor/core/src/core/uritemplate/helpers.h index ee3096c2f..152261d28 100644 --- a/vendor/core/src/core/uritemplate/helpers.h +++ b/vendor/core/src/core/uritemplate/helpers.h @@ -348,9 +348,10 @@ auto parse_expression(const std::string_view input) -> std::conditional_t, URITemplateParseResult> { if constexpr (std::is_same_v) { - if (input.empty() || input[0] == '{') { - return std::nullopt; - } + // A literal is read last of all, after everything that opens an expression + // has either taken what stands here or refused the template outright, and + // the walk that asks only ever hands over what it has left to read + assert(!input.empty() && input[0] != '{'); std::size_t position = 0; while (position < input.size()) { @@ -405,10 +406,11 @@ auto parse_expression(const std::string_view input) if (input.size() < 2) { throw URITemplateParseError(1); } - // Not a simple variable if it has an operator - if (is_operator(input[1])) { - return std::nullopt; - } + + // RFC 6570 Section 2.2 has an operator name which expansion stands here, + // and every one of those is read before this is, so what reaches here + // never carries one + assert(!is_operator(input[1])); var_start = 1; } diff --git a/vendor/core/src/core/uritemplate/uritemplate_router.cc b/vendor/core/src/core/uritemplate/uritemplate_router.cc index 72ca9b81b..b528ecd12 100644 --- a/vendor/core/src/core/uritemplate/uritemplate_router.cc +++ b/vendor/core/src/core/uritemplate/uritemplate_router.cc @@ -729,7 +729,11 @@ auto URITemplateRouter::match(const std::string_view path, ++position; } - if ((current != nullptr) && current->identifier == 0 && current->variable && + // Every way out of the walk above either answers on its own or settles on a + // node, which is what stepping past that node's own literals relies on too + assert(current != nullptr); + + if (current->identifier == 0 && current->variable && current->variable->type == NodeType::OptionalExpansion) { assert(variable_index <= std::numeric_limits::max()); @@ -739,11 +743,8 @@ auto URITemplateRouter::match(const std::string_view path, current->variable->context); } - return (current != nullptr) - ? finalize_match(this->otherwise_, current->identifier, - current->context) - : finalize_match(this->otherwise_, this->root_.identifier, - this->root_.context); + return finalize_match(this->otherwise_, current->identifier, + current->context); } } // namespace sourcemeta::core diff --git a/vendor/core/src/core/uritemplate/uritemplate_router_view.cc b/vendor/core/src/core/uritemplate/uritemplate_router_view.cc index a06320ee7..3ba4254f8 100644 --- a/vendor/core/src/core/uritemplate/uritemplate_router_view.cc +++ b/vendor/core/src/core/uritemplate/uritemplate_router_view.cc @@ -878,13 +878,11 @@ auto URITemplateRouterView::arguments( } switch (type_tag) { - case ARGUMENT_TYPE_STRING: { - const std::string_view string_value{ - reinterpret_cast(this->data_ + cursor), - value_length}; - callback(name, string_value); + case ARGUMENT_TYPE_STRING: + callback(name, std::string_view{reinterpret_cast( + this->data_ + cursor), + value_length}); break; - } case ARGUMENT_TYPE_INTEGER: { if (value_length != 8) { diff --git a/vendor/core/src/lang/io/io.cc b/vendor/core/src/lang/io/io.cc index bde3c58c3..2bdca437e 100644 --- a/vendor/core/src/lang/io/io.cc +++ b/vendor/core/src/lang/io/io.cc @@ -146,14 +146,18 @@ auto weakly_canonical(const std::filesystem::path &path) const auto absolute_path{ path.is_absolute() ? path : std::filesystem::absolute(path)}; - // On Linux, FIFO files (like /dev/fd/XX due to process substitution) - // cannot be made canonical - // See https://github.com/sourcemeta/jsonschema/issues/252 - if (std::filesystem::is_fifo(absolute_path)) { - return normalize(absolute_path); - } - try { + // On Linux, FIFO files (like /dev/fd/XX due to process substitution) + // cannot be made canonical + // See https://github.com/sourcemeta/jsonschema/issues/252 + // + // Asking what the path is can fail for the same reasons canonicalising it + // can, so it is asked from inside here rather than ahead of it, where a + // failure would travel on without the naming below ever seeing it + if (std::filesystem::is_fifo(absolute_path)) { + return normalize(absolute_path); + } + return normalize(std::filesystem::weakly_canonical(absolute_path)); } catch (const std::filesystem::filesystem_error &error) { if (error.code() == std::errc::no_such_file_or_directory) { diff --git a/vendor/core/src/lang/numeric/big_coefficient.h b/vendor/core/src/lang/numeric/big_coefficient.h index 1817e44b6..76263d35e 100644 --- a/vendor/core/src/lang/numeric/big_coefficient.h +++ b/vendor/core/src/lang/numeric/big_coefficient.h @@ -110,7 +110,10 @@ constexpr std::int64_t COMPACT_MAX = class BigCoefficient { static constexpr std::uint32_t INLINE_CAPACITY = 4; - std::array inline_words_; + // Every limb of the store stays written, and the ones at or past the length + // stay zero, which is what lets a value of fewer limbs than the store holds + // be read a limb at a time without reaching for one that was never written + std::array inline_words_{}; [[nodiscard]] auto is_inline() const -> bool { return this->capacity <= INLINE_CAPACITY; @@ -129,7 +132,6 @@ class BigCoefficient { if (requested_capacity <= INLINE_CAPACITY) { this->words = this->inline_words_.data(); this->capacity = INLINE_CAPACITY; - this->inline_words_.fill(0); } else { this->words = new std::uint64_t[requested_capacity](); this->capacity = requested_capacity; @@ -145,15 +147,14 @@ class BigCoefficient { BigCoefficient(BigCoefficient &&other) noexcept : length{other.length}, capacity{other.capacity} { if (other.is_inline()) { - std::copy(other.inline_words_.data(), - other.inline_words_.data() + other.length, - this->inline_words_.data()); + this->inline_words_ = other.inline_words_; this->words = this->inline_words_.data(); } else { this->words = other.words; other.words = other.inline_words_.data(); } + other.inline_words_.fill(0); other.length = 0; other.capacity = INLINE_CAPACITY; } @@ -167,15 +168,14 @@ class BigCoefficient { this->length = other.length; this->capacity = other.capacity; if (other.is_inline()) { - std::copy(other.inline_words_.data(), - other.inline_words_.data() + other.length, - this->inline_words_.data()); + this->inline_words_ = other.inline_words_; this->words = this->inline_words_.data(); } else { this->words = other.words; other.words = other.inline_words_.data(); } + other.inline_words_.fill(0); other.length = 0; other.capacity = INLINE_CAPACITY; } @@ -260,6 +260,9 @@ class BigCoefficient { std::copy(this->words + zero_words, this->words + this->length, this->words); this->length -= zero_words; + // What the shift leaves behind is no longer part of the value + std::fill(this->words + this->length, + this->words + this->length + zero_words, 0ULL); total_stripped += static_cast(zero_words) * BASE_DIGITS; } diff --git a/vendor/core/src/lang/parallel/include/sourcemeta/core/parallel_for_each.h b/vendor/core/src/lang/parallel/include/sourcemeta/core/parallel_for_each.h index 65b59c38b..4ed2bd93c 100644 --- a/vendor/core/src/lang/parallel/include/sourcemeta/core/parallel_for_each.h +++ b/vendor/core/src/lang/parallel/include/sourcemeta/core/parallel_for_each.h @@ -7,7 +7,7 @@ #include // std::exception_ptr, std::current_exception, std::rethrow_exception #include // std::function #include // std::input_iterator, std::iter_reference_t -#include // std::mutex, std::scoped_lock +#include // std::mutex, std::scoped_lock, std::unique_lock #include // std::queue #include // std::runtime_error #include // std::thread @@ -132,17 +132,18 @@ auto parallel_for_each( &exception_mutex, effective_parallelism, total] { try { while (true) { - Iterator iterator; - std::size_t cursor{0}; - { - std::scoped_lock lock{queue_mutex}; - if (tasks.empty()) { - return; - } - iterator = tasks.front(); - cursor = total - tasks.size() + 1; - tasks.pop(); + // The lock is given up before the work runs, as holding it across the + // callback would leave the other workers waiting on the queue for as + // long as this one takes + std::unique_lock lock{queue_mutex}; + if (tasks.empty()) { + return; } + + const auto iterator{tasks.front()}; + const auto cursor{total - tasks.size() + 1}; + tasks.pop(); + lock.unlock(); effective_callback(*iterator, effective_parallelism, cursor); } } catch (...) {