Browse Source

fix: validation on RelativePointer for e.g. "01/A"

Sam Jaffe 3 months ago
parent
commit
8db4e3d2e4
1 changed files with 3 additions and 0 deletions
  1. 3 0
      include/jvalidate/detail/relative_pointer.h

+ 3 - 0
include/jvalidate/detail/relative_pointer.h

@@ -16,6 +16,7 @@ public:
     if (path == "0") {
       return;
     }
+
     if (auto pos = path.find('/'); pos != path.npos) {
       pointer_ = Pointer(path.substr(pos));
       path.remove_suffix(path.size() - pos);
@@ -23,6 +24,8 @@ public:
       requests_key_ = true;
       path.remove_suffix(1);
     }
+
+    EXPECT_M(path == "0" || not path.starts_with("0"), "Cannot zero-prefix a relative pointer");
     parent_steps_ = from_str<size_t>(path);
   }