-
-
Notifications
You must be signed in to change notification settings - Fork 18
Restrict disallow on Draft 3 canonicalizer in more cases
#875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,8 +35,22 @@ class DisallowDoubleNegation final : public SchemaTransformRule { | |
| ONLY_CONTINUE_IF( | ||
| wraps_single_constraint(schema, "disallow", walker, vocabularies)); | ||
|
|
||
| ONLY_CONTINUE_IF(!frame.has_references_through( | ||
| location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); | ||
| // Collapsing the chain dissolves every intermediate `disallow` wrapper, so | ||
| // a reference targeting any of them has no valid new home: bail. A | ||
| // reference into the surviving innermost schema relocates with it (handled | ||
| // by `rereference`) | ||
| auto wrapper{location.pointer}; | ||
| const sourcemeta::core::JSON *node{&disallow->at(0)}; | ||
| while (is_single_negation(*node)) { | ||
| wrapper.push_back(std::cref(KEYWORD)); | ||
| wrapper.push_back(static_cast<std::size_t>(0)); | ||
| if (frame.has_references_to(wrapper)) { | ||
| return false; | ||
| } | ||
|
|
||
| node = &node->at(KEYWORD).at(0); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -55,6 +69,23 @@ class DisallowDoubleNegation final : public SchemaTransformRule { | |
| } | ||
| } | ||
|
|
||
| [[nodiscard]] auto rereference(const std::string_view, const Pointer &, | ||
| const Pointer &target, | ||
| const Pointer ¤t) const | ||
| -> Pointer override { | ||
| auto old_prefix{current.concat({"disallow", 0, "disallow", 0})}; | ||
| while ( | ||
| target.starts_with(old_prefix.concat({"disallow", 0, "disallow", 0}))) { | ||
| old_prefix = old_prefix.concat({"disallow", 0, "disallow", 0}); | ||
| } | ||
|
|
||
| if (!target.starts_with(old_prefix)) { | ||
| return target; | ||
| } | ||
|
|
||
| return target.rebase(old_prefix, current); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| } | ||
|
|
||
| private: | ||
| static auto is_single_negation(const sourcemeta::core::JSON &schema) -> bool { | ||
| return schema.is_object() && schema.size() == 1 && | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.