|
|
@@ -3,6 +3,7 @@
|
|
|
#include <algorithm>
|
|
|
#include <cassert>
|
|
|
#include <iostream>
|
|
|
+#include <jvalidate/detail/expect.h>
|
|
|
#include <jvalidate/detail/number.h>
|
|
|
#include <string>
|
|
|
#include <string_view>
|
|
|
@@ -42,7 +43,7 @@ public:
|
|
|
* valid - and therefore that an invalidly formatter pointer string will
|
|
|
* point to somewhere non-existant (since it will be used in schema handling)
|
|
|
*/
|
|
|
- Pointer(std::string_view path) {
|
|
|
+ Pointer(std::string_view path, bool strict = false) {
|
|
|
if (path.empty()) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -63,8 +64,9 @@ public:
|
|
|
// than '/' and '~' to be handled in all contexts.
|
|
|
// TODO(samjaffe): Only do this if enc is hex-like (currently throws?)
|
|
|
if (in[i] == '%') {
|
|
|
- char const enc[3] = {in[i + 1], in[i + 2], '\0'};
|
|
|
+ std::string_view enc = std::string_view(in).substr(i + 1, 2);
|
|
|
in.replace(i, 3, 1, from_str<char>(enc, 16));
|
|
|
+ continue;
|
|
|
} else if (in[i] != '~') {
|
|
|
// Not a special char-sequence, does not need massaging
|
|
|
continue;
|
|
|
@@ -77,6 +79,8 @@ public:
|
|
|
in.replace(i, 2, 1, '~');
|
|
|
} else if (in[i + 1] == '1') {
|
|
|
in.replace(i, 2, 1, '/');
|
|
|
+ } else {
|
|
|
+ JVALIDATE_THROW(std::runtime_error, "Illegal ~ code");
|
|
|
}
|
|
|
}
|
|
|
tokens_.push_back(std::move(in));
|
|
|
@@ -84,6 +88,7 @@ public:
|
|
|
|
|
|
// JSON-Pointers are required to start with a '/' although we only enforce
|
|
|
// that rule in Reference.
|
|
|
+ EXPECT_M(not strict || path.starts_with('/'), "JSON Pointer must start with '/'");
|
|
|
path.remove_prefix(1);
|
|
|
// The rules of JSON-Pointer is that if a token were to contain a '/' as a
|
|
|
// strict character: then that character would be escaped, using the above
|