Procházet zdrojové kódy

fix: proper formulation of RelativePointer

Sam Jaffe před 2 týdny
rodič
revize
ca74d7a5f6
1 změnil soubory, kde provedl 6 přidání a 9 odebrání
  1. 6 9
      include/jvalidate/detail/relative_pointer.h

+ 6 - 9
include/jvalidate/detail/relative_pointer.h

@@ -33,29 +33,26 @@ public:
     }
 
     RelativePointer rval;
-    if (auto pos = path.find('/'); pos != path.npos) {
+    if (size_t pos = path.find('/'); pos != path.npos) {
       // Handle the JSON-Pointer version
       expected ptr = Pointer::parse(path.substr(pos));
       JVALIDATE_PROPIGATE_UNEXPECTED(ptr);
       rval.pointer_ = *std::move(ptr);
       path.remove_suffix(path.size() - pos);
-    } else if (path.back() == '#') {
+    } else if (path.ends_with('#')) {
       rval.requests_key_ = true;
       path.remove_suffix(1);
     }
 
-    if (path.find_first_not_of("0123456789") != std::string_view::npos) {
-      return unexpected("RelativePointer must end in a pointer, or a '#'");
+    if (path.starts_with('0') && path != "0") {
+      return unexpected("Cannot zero-prefix a relative pointer");
     }
 
     size_t read = 0;
     expected parent_steps = parse_integer<size_t>(path, {.read = read});
-
-    JVALIDATE_PROPIGATE_UNEXPECTED(parent_steps.transform_error(to_message));
-    EXPECT_M(read == path.size(), "Extra chars in RelativePointer");
-
-    // Will throw an exception if path contains any non-numeric characters, or
+    // Will return unexpected if path contains any non-numeric characters, or
     // if path represents a number that is out of the bounds of a size_t.
+    JVALIDATE_PROPIGATE_UNEXPECTED(parent_steps.transform_error(to_message));
     rval.parent_steps_ = *parent_steps;
     return rval;
   }