Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strange behaviour with json_pointer and .contains() #1811

Closed
lianguage opened this issue Oct 24, 2019 · 1 comment
Closed

strange behaviour with json_pointer and .contains() #1811

lianguage opened this issue Oct 24, 2019 · 1 comment

Comments

@lianguage
Copy link

lianguage commented Oct 24, 2019

It seems like the contains method is very picky about how json_pointers are passed in and I can't figure out why. See the example below for what I mean

nlohmann::json j_example2 = 
{ 
   {
      "asdf",
      {
         {
            {"fname","qui-gon"},
         },
         {
            {"fname","aramis"},
         },
         {
            {"fname","donald"},
         }
      }
   }
};

   std::string asdf = "/asdf";

   //these return true
   REQUIRE(j_example2.contains(nlohmann::json::json_pointer(asdf)));
   REQUIRE(j_example2.contains(nlohmann::json::json_pointer("/asdf")));
   REQUIRE(j_example2.contains("/asdf"_json_pointer));
   REQUIRE(j_example2.contains("/asdf/0/fname"_json_pointer));
   
   //this returns false
   nlohmann::json::json_pointer pointer(asdf);
   REQUIRE(j_example2.contains(pointer));
   
   //this causes some kind of crash
   nlohmann::json::json_pointer pointer2 = "/asdf"_json_pointer;
   REQUIRE(j_example2.contains(pointer2));

I'm using version 3.7.0

@lianguage
Copy link
Author

I'm gonna test this first with some different flags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant