diff --git a/src/core/jsonpointer/jsonpointer.cc b/src/core/jsonpointer/jsonpointer.cc index 70be9a264..0b9442c61 100644 --- a/src/core/jsonpointer/jsonpointer.cc +++ b/src/core/jsonpointer/jsonpointer.cc @@ -5,7 +5,6 @@ #include #include -#include "grammar.h" #include "parser.h" #include "stringify.h" @@ -309,13 +308,10 @@ auto to_pointer(const JSON &document) -> Pointer { auto to_pointer(const std::basic_string> &input) -> Pointer { - std::basic_stringstream> - stream; - stream << internal::token_pointer_quote; - stream << input; - stream << internal::token_pointer_quote; - return to_pointer(parse_json(stream)); + std::basic_istringstream> + stream{input}; + return parse_pointer(stream); } auto to_pointer(const WeakPointer &pointer) -> Pointer { diff --git a/test/jsonpointer/jsonpointer_parse_error_test.cc b/test/jsonpointer/jsonpointer_parse_error_test.cc index 0af59c8d6..be7c5599d 100644 --- a/test/jsonpointer/jsonpointer_parse_error_test.cc +++ b/test/jsonpointer/jsonpointer_parse_error_test.cc @@ -4,21 +4,8 @@ #include #include -#include #include -#define EXPECT_JSON_PARSE_ERROR(input) \ - try { \ - std::ostringstream stream; \ - stream << "\"" << (input) << "\""; \ - sourcemeta::core::parse_json(stream.str()); \ - FAIL() << "The parse function was expected to throw"; \ - } catch (const sourcemeta::core::JSONParseError &) { \ - SUCCEED(); \ - } catch (const std::exception &) { \ - FAIL() << "The parse operation threw an unexpected error"; \ - } - #define EXPECT_POINTER_PARSE_ERROR(input, expected_column) \ try { \ sourcemeta::core::to_pointer(input); \ @@ -89,452 +76,3 @@ TEST(JSONPointer_parse_error, foo_tilde_tilde) { EXPECT_POINTER_PARSE_ERROR(input, 6); EXPECT_FALSE(sourcemeta::core::is_pointer(input)); } - -TEST(JSONPointer_parse_error, backspace) { - const std::string input{"/\b"}; - EXPECT_JSON_PARSE_ERROR(input); - // RFC 6901: control characters are valid in unescaped production - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, formfeed) { - const std::string input{"/\f"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, newline) { - const std::string input{"/\n"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, carriage_return) { - const std::string input{"/\r"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, tab) { - const std::string input{"/\t"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, null) { - // See https://stackoverflow.com/a/164274 - using namespace std::string_literals; - const std::string input{"/\0"s}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, backspace_within_word) { - const std::string input{"/foo\bbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, formfeed_within_word) { - const std::string input{"/foo\fbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, newline_within_word) { - const std::string input{"/foo\nbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, carriage_return_within_word) { - const std::string input{"/foo\rbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, tab_within_word) { - const std::string input{"/foo\tbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, null_within_word) { - // See https://stackoverflow.com/a/164274 - using namespace std::string_literals; - const std::string input{"/foo\0bar"s}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0001) { - const std::string input{"/\u0001"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0002) { - const std::string input{"/\u0002"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0003) { - const std::string input{"/\u0003"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0004) { - const std::string input{"/\u0004"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0005) { - const std::string input{"/\u0005"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0006) { - const std::string input{"/\u0006"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0007) { - const std::string input{"/\u0007"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0008) { - const std::string input{"/\u0008"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0009) { - const std::string input{"/\u0009"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000A) { - const std::string input{"/\u000A"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000B) { - const std::string input{"/\u000B"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000C) { - const std::string input{"/\u000C"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000D) { - const std::string input{"/\u000D"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000E) { - const std::string input{"/\u000E"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000F) { - const std::string input{"/\u000F"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0010) { - const std::string input{"/\u0010"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0011) { - const std::string input{"/\u0011"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0012) { - const std::string input{"/\u0012"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0013) { - const std::string input{"/\u0013"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0014) { - const std::string input{"/\u0014"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0015) { - const std::string input{"/\u0015"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0016) { - const std::string input{"/\u0016"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0017) { - const std::string input{"/\u0017"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0018) { - const std::string input{"/\u0018"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0019) { - const std::string input{"/\u0019"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001A) { - const std::string input{"/\u001A"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001B) { - const std::string input{"/\u001B"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001C) { - const std::string input{"/\u001C"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001D) { - const std::string input{"/\u001D"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001E) { - const std::string input{"/\u001E"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001F) { - const std::string input{"/\u001F"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0001_within_word) { - const std::string input{"/foo\u0001bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0002_within_word) { - const std::string input{"/foo\u0002bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0003_within_word) { - const std::string input{"/foo\u0003bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0004_within_word) { - const std::string input{"/foo\u0004bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0005_within_word) { - const std::string input{"/foo\u0005bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0006_within_word) { - const std::string input{"/foo\u0006bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0007_within_word) { - const std::string input{"/foo\u0007bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0008_within_word) { - const std::string input{"/foo\u0008bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0009_within_word) { - const std::string input{"/foo\u0009bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000A_within_word) { - const std::string input{"/foo\u000Abar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000B_within_word) { - const std::string input{"/foo\u000Bbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000C_within_word) { - const std::string input{"/foo\u000Cbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000D_within_word) { - const std::string input{"/foo\u000Dbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000E_within_word) { - const std::string input{"/foo\u000Ebar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_000F_within_word) { - const std::string input{"/foo\u000Fbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0010_within_word) { - const std::string input{"/foo\u0010bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0011_within_word) { - const std::string input{"/foo\u0011bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0012_within_word) { - const std::string input{"/foo\u0012bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0013_within_word) { - const std::string input{"/foo\u0013bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0014_within_word) { - const std::string input{"/foo\u0014bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0015_within_word) { - const std::string input{"/foo\u0015bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0016_within_word) { - const std::string input{"/foo\u0016bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0017_within_word) { - const std::string input{"/foo\u0017bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0018_within_word) { - const std::string input{"/foo\u0018bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_0019_within_word) { - const std::string input{"/foo\u0019bar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001A_within_word) { - const std::string input{"/foo\u001Abar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001B_within_word) { - const std::string input{"/foo\u001Bbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001C_within_word) { - const std::string input{"/foo\u001Cbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001D_within_word) { - const std::string input{"/foo\u001Dbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001E_within_word) { - const std::string input{"/foo\u001Ebar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} - -TEST(JSONPointer_parse_error, unicode_001F_within_word) { - const std::string input{"/foo\u001Fbar"}; - EXPECT_JSON_PARSE_ERROR(input); - EXPECT_TRUE(sourcemeta::core::is_pointer(input)); -} diff --git a/test/jsonpointer/jsonpointer_parse_test.cc b/test/jsonpointer/jsonpointer_parse_test.cc index 935e87ca5..ef6abb518 100644 --- a/test/jsonpointer/jsonpointer_parse_test.cc +++ b/test/jsonpointer/jsonpointer_parse_test.cc @@ -3,7 +3,6 @@ #include #include -#include #include TEST(JSONPointer_parse, empty_string) { @@ -303,36 +302,34 @@ TEST(JSONPointer_parse, pipe) { } TEST(JSONPointer_parse, backslash_after_letter) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/i\\\\j")); + EXPECT_TRUE(sourcemeta::core::is_pointer("/i\\j")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/i\\\\j"); + sourcemeta::core::to_pointer("/i\\j"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "i\\j"); } TEST(JSONPointer_parse, backslash) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/\\\\")); - const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/\\\\"); + EXPECT_TRUE(sourcemeta::core::is_pointer("/\\")); + const sourcemeta::core::Pointer pointer = sourcemeta::core::to_pointer("/\\"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "\\"); } TEST(JSONPointer_parse, double_quote_after_letter) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/k\\\"l")); + EXPECT_TRUE(sourcemeta::core::is_pointer("/k\"l")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/k\\\"l"); + sourcemeta::core::to_pointer("/k\"l"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "k\"l"); } TEST(JSONPointer_parse, double_quote) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/\\\"")); - const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/\\\""); + EXPECT_TRUE(sourcemeta::core::is_pointer("/\"")); + const sourcemeta::core::Pointer pointer = sourcemeta::core::to_pointer("/\""); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "\""); @@ -364,9 +361,9 @@ TEST(JSONPointer_parse, escaped_slash) { } TEST(JSONPointer_parse, escaped_slash_with_backslash) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/\\\\/")); + EXPECT_TRUE(sourcemeta::core::is_pointer("/\\/")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/\\\\/"); + sourcemeta::core::to_pointer("/\\/"); EXPECT_EQ(pointer.size(), 2); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "\\"); @@ -375,9 +372,9 @@ TEST(JSONPointer_parse, escaped_slash_with_backslash) { } TEST(JSONPointer_parse, escaped_slash_with_backslash_after_letter) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/x\\\\/")); + EXPECT_TRUE(sourcemeta::core::is_pointer("/x\\/")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/x\\\\/"); + sourcemeta::core::to_pointer("/x\\/"); EXPECT_EQ(pointer.size(), 2); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "x\\"); @@ -451,147 +448,138 @@ TEST(JSONPointer_parse, hyphen_slash_hyphen) { EXPECT_EQ(pointer.at(1).to_property(), "-"); } -TEST(JSONPointer_parse, escaped_quote_within_string) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\\\"bar")); +TEST(JSONPointer_parse, quote_within_string) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\"bar")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/foo\\\"bar"); + sourcemeta::core::to_pointer("/foo\"bar"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "foo\"bar"); } -TEST(JSONPointer_parse, escaped_quote) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/\\\"")); - const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/\\\""); +TEST(JSONPointer_parse, quote) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\"")); + const sourcemeta::core::Pointer pointer = sourcemeta::core::to_pointer("/\""); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "\""); } -TEST(JSONPointer_parse, escaped_backslash_within_string) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\\\\bar")); +TEST(JSONPointer_parse, backslash_within_string) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\\bar")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/foo\\\\bar"); + sourcemeta::core::to_pointer("/foo\\bar"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "foo\\bar"); } -TEST(JSONPointer_parse, escaped_backslash) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/\\\\")); - const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/\\\\"); +TEST(JSONPointer_parse, backslash_only) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\\")); + const sourcemeta::core::Pointer pointer = sourcemeta::core::to_pointer("/\\"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "\\"); } -TEST(JSONPointer_parse, control_backslash_backspace) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/\\b")); - const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/\\b"); +TEST(JSONPointer_parse, control_backspace) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\b")); + const sourcemeta::core::Pointer pointer = sourcemeta::core::to_pointer("/\b"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "\b"); } -TEST(JSONPointer_parse, control_backslash_backspace_within_string) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\\bbar")); +TEST(JSONPointer_parse, control_backspace_within_string) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\bbar")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/foo\\bbar"); + sourcemeta::core::to_pointer("/foo\bbar"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "foo\bbar"); } -TEST(JSONPointer_parse, control_backslash_formfeed) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/\\f")); - const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/\\f"); +TEST(JSONPointer_parse, control_formfeed) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\f")); + const sourcemeta::core::Pointer pointer = sourcemeta::core::to_pointer("/\f"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "\f"); } -TEST(JSONPointer_parse, control_backslash_formfeed_within_string) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\\fbar")); +TEST(JSONPointer_parse, control_formfeed_within_string) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\fbar")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/foo\\fbar"); + sourcemeta::core::to_pointer("/foo\fbar"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "foo\fbar"); } -TEST(JSONPointer_parse, control_backslash_newline) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/\\n")); - const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/\\n"); +TEST(JSONPointer_parse, control_newline) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\n")); + const sourcemeta::core::Pointer pointer = sourcemeta::core::to_pointer("/\n"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "\n"); } -TEST(JSONPointer_parse, control_backslash_newline_within_string) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\\nbar")); +TEST(JSONPointer_parse, control_newline_within_string) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\nbar")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/foo\\nbar"); + sourcemeta::core::to_pointer("/foo\nbar"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "foo\nbar"); } -TEST(JSONPointer_parse, control_backslash_carriage) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/\\r")); - const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/\\r"); +TEST(JSONPointer_parse, control_carriage) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\r")); + const sourcemeta::core::Pointer pointer = sourcemeta::core::to_pointer("/\r"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "\r"); } -TEST(JSONPointer_parse, control_backslash_carriage_within_string) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\\rbar")); +TEST(JSONPointer_parse, control_carriage_within_string) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\rbar")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/foo\\rbar"); + sourcemeta::core::to_pointer("/foo\rbar"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "foo\rbar"); } -TEST(JSONPointer_parse, control_backslash_tab) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/\\t")); - const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/\\t"); +TEST(JSONPointer_parse, control_tab) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\t")); + const sourcemeta::core::Pointer pointer = sourcemeta::core::to_pointer("/\t"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "\t"); } -TEST(JSONPointer_parse, control_backslash_tab_within_string) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\\tbar")); +TEST(JSONPointer_parse, control_tab_within_string) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\tbar")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/foo\\tbar"); + sourcemeta::core::to_pointer("/foo\tbar"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "foo\tbar"); } -TEST(JSONPointer_parse, property_with_unicode_code_point) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\\u002Abar")); +TEST(JSONPointer_parse, property_with_asterisk) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo*bar")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("/foo\\u002Abar"); + sourcemeta::core::to_pointer("/foo*bar"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); - EXPECT_EQ(pointer.at(0).to_property(), "foo\u002Abar"); + EXPECT_EQ(pointer.at(0).to_property(), "foo*bar"); } -TEST(JSONPointer_parse, unicode_slashes) { - // The raw string starts with '\', not '/' - invalid per RFC 6901. - // to_pointer() succeeds because the JSON parser interprets \u002F as '/' - EXPECT_FALSE(sourcemeta::core::is_pointer("\\u002Ffoo\\u002Fbar")); +TEST(JSONPointer_parse, two_tokens) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo/bar")); const sourcemeta::core::Pointer pointer = - sourcemeta::core::to_pointer("\\u002Ffoo\\u002Fbar"); + sourcemeta::core::to_pointer("/foo/bar"); EXPECT_EQ(pointer.size(), 2); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "foo"); @@ -613,12 +601,90 @@ TEST(JSONPointer_parse, regex_caret) { } TEST(JSONPointer_parse, regex_backslash) { - EXPECT_TRUE(sourcemeta::core::is_pointer("/[\\\\-]")); + EXPECT_TRUE(sourcemeta::core::is_pointer("/[\\-]")); const sourcemeta::core::Pointer pointer = - // Needs escaping because here we are interpreting as a C string and not - // as a JSON string - sourcemeta::core::to_pointer("/[\\\\-]"); + sourcemeta::core::to_pointer("/[\\-]"); EXPECT_EQ(pointer.size(), 1); EXPECT_TRUE(pointer.at(0).is_property()); EXPECT_EQ(pointer.at(0).to_property(), "[\\-]"); } + +TEST(JSONPointer_parse, json_escape_backslash_n_treated_literally) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\\nbar")); + const auto pointer = sourcemeta::core::to_pointer("/foo\\nbar"); + EXPECT_EQ(pointer.size(), 1); + EXPECT_TRUE(pointer.at(0).is_property()); + EXPECT_EQ(pointer.at(0).to_property(), "foo\\nbar"); +} + +TEST(JSONPointer_parse, json_escape_unicode_treated_literally) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\\u002Abar")); + const auto pointer = sourcemeta::core::to_pointer("/foo\\u002Abar"); + EXPECT_EQ(pointer.size(), 1); + EXPECT_TRUE(pointer.at(0).is_property()); + EXPECT_EQ(pointer.at(0).to_property(), "foo\\u002Abar"); +} + +TEST(JSONPointer_parse, unicode_0001) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\u0001")); + const auto pointer = sourcemeta::core::to_pointer("/\u0001"); + EXPECT_EQ(pointer.size(), 1); + EXPECT_TRUE(pointer.at(0).is_property()); + EXPECT_EQ(pointer.at(0).to_property(), "\u0001"); +} + +TEST(JSONPointer_parse, unicode_0002) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\u0002")); + const auto pointer = sourcemeta::core::to_pointer("/\u0002"); + EXPECT_EQ(pointer.size(), 1); + EXPECT_TRUE(pointer.at(0).is_property()); + EXPECT_EQ(pointer.at(0).to_property(), "\u0002"); +} + +TEST(JSONPointer_parse, unicode_000B) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\u000B")); + const auto pointer = sourcemeta::core::to_pointer("/\u000B"); + EXPECT_EQ(pointer.size(), 1); + EXPECT_TRUE(pointer.at(0).is_property()); + EXPECT_EQ(pointer.at(0).to_property(), "\u000B"); +} + +TEST(JSONPointer_parse, unicode_000E) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\u000E")); + const auto pointer = sourcemeta::core::to_pointer("/\u000E"); + EXPECT_EQ(pointer.size(), 1); + EXPECT_TRUE(pointer.at(0).is_property()); + EXPECT_EQ(pointer.at(0).to_property(), "\u000E"); +} + +TEST(JSONPointer_parse, unicode_001F) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/\u001F")); + const auto pointer = sourcemeta::core::to_pointer("/\u001F"); + EXPECT_EQ(pointer.size(), 1); + EXPECT_TRUE(pointer.at(0).is_property()); + EXPECT_EQ(pointer.at(0).to_property(), "\u001F"); +} + +TEST(JSONPointer_parse, unicode_0001_within_word) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\u0001bar")); + const auto pointer = sourcemeta::core::to_pointer("/foo\u0001bar"); + EXPECT_EQ(pointer.size(), 1); + EXPECT_TRUE(pointer.at(0).is_property()); + EXPECT_EQ(pointer.at(0).to_property(), "foo\u0001bar"); +} + +TEST(JSONPointer_parse, unicode_000E_within_word) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\u000Ebar")); + const auto pointer = sourcemeta::core::to_pointer("/foo\u000Ebar"); + EXPECT_EQ(pointer.size(), 1); + EXPECT_TRUE(pointer.at(0).is_property()); + EXPECT_EQ(pointer.at(0).to_property(), "foo\u000Ebar"); +} + +TEST(JSONPointer_parse, unicode_001F_within_word) { + EXPECT_TRUE(sourcemeta::core::is_pointer("/foo\u001Fbar")); + const auto pointer = sourcemeta::core::to_pointer("/foo\u001Fbar"); + EXPECT_EQ(pointer.size(), 1); + EXPECT_TRUE(pointer.at(0).is_property()); + EXPECT_EQ(pointer.at(0).to_property(), "foo\u001Fbar"); +}