Sfoglia il codice sorgente

fix: relative URI must be rootless

Sam Jaffe 1 anno fa
parent
commit
c50f742367
2 ha cambiato i file con 5 aggiunte e 3 eliminazioni
  1. 4 2
      include/jvalidate/reference_handler.h
  2. 1 1
      include/jvalidate/uri.h

+ 4 - 2
include/jvalidate/reference_handler.h

@@ -138,9 +138,11 @@ private:
       root = detail::RootReference(schema[id].as_string());
       if (root.uri().empty()) {
         root = detail::RootReference(where.uri(), root.anchor());
-      } else if (root.uri().is_relative() && not where.uri().empty()) {
+      } else if (not root.uri().is_rootless() || where.uri().empty()) {
+        // By definition - rootless URIs cannot be relative
+      } else if (root.uri().is_relative()) {
         root = detail::RootReference(where.uri().parent() / root.uri(), root.anchor());
-      } else if (root.uri().is_rootless() && not where.uri().empty()) {
+      } else {
         root = detail::RootReference(where.uri().root() / root.uri(), root.anchor());
       }
 

+ 1 - 1
include/jvalidate/uri.h

@@ -40,7 +40,7 @@ public:
   }
 
   bool is_rootless() const { return scheme_ == 0; }
-  bool is_relative() const { return uri_[resource_] != '/'; }
+  bool is_relative() const { return is_rootless() && uri_[resource_] != '/'; }
   std::string_view scheme() const { return std::string_view(uri_).substr(0, scheme_); }
   std::string_view resource() const { return std::string_view(uri_).substr(resource_); }