Bläddra i källkod

fix: properly setup dynamic reference context when jumping to a different root URI

Sam Jaffe 2 veckor sedan
förälder
incheckning
e51d887a72
1 ändrade filer med 10 tillägg och 0 borttagningar
  1. 10 0
      include/jvalidate/schema.h

+ 10 - 0
include/jvalidate/schema.h

@@ -268,6 +268,16 @@ private:
     detail::Reference lexical = context.ref.canonicalize(ref, context.where, dynamic_reference);
     detail::Reference dynamic = dynamic_reference ? lexical : context.dynamic_where / "$ref";
 
+    detail::OnBlockExit scope;
+    if (lexical.uri() != context.where.uri()) {
+      // Whenever we change base URIs, we need to recalculate our dynamic_scope.
+      // Otherwise, it is possible for a chain of $ref statements to
+      // accidentally leave us ignoring $dynamicAnchor contexts.
+      // This is demonstrated by the test descriptor in JSON-Schema-Test-Suite:
+      //   "$dynamicRef avoids the root of each schema, but scopes are still registered"
+      scope = context.ref.dynamic_scope(lexical);
+    }
+
     if (std::optional cached = from_cache(dynamic)) {
       return *cached;
     }