🐛 fixed callback-related issue (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
This commit is contained in:
		
							parent
							
								
									b5c54b41fd
								
							
						
					
					
						commit
						e33b31e6aa
					
				
					 26 changed files with 97 additions and 18880 deletions
				
			
		| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/TarF5pPn9NtHQjhf"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/7HlactSAaECZWYmb"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/tfI8DuCuZs3VB9VF"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/3OPLSVPyweUyEHaX"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/E1HQedkl1zo48WW5"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/4bn447WQbTERfBaL"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/mya8dUDcDDVoUlBZ"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/AHKW5EMQN4YQ68TY"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/sMmEKxW5MGOgLC7z"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/J0KoQF8sOpdMg4kN"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/qq29jfETq7nZRrh5"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/uuQK0DAjhbSd96K6"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/0zdmfNQCe4TMw0iI"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/eFzRNyod3g4aVkvl"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/YrUqrUFMD7JHwSQR"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/IvgowYGaX0SgOFIG"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/wXcm4ObnoaXw7CRt"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/ckGZIBookDffV00n"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/vxt8d8qvYorXS2yq"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/oKnfnFrLHG8H1OAl"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/TSNxHmegVwLW2pXf"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/i3BBhl7Ub5y9b0yp"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/l3zNo3YKC2X8yAw9"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/sGdJMOaJnFNJBtH7"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/Mf7A6JtvqT1Na7Pk"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/UZgRBIeqdZhm6M8F"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/oa6BVkBXjG8DNkzX"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/VThe0hdMSUdNSOLK"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/QXdl4yzts3qPeZ0U"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/QZgjsR0PiAw2Lqpk"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/8ObNa6ejw4BXQ5qG"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/hFd1W46W2Hb81sHN"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/4bQSclXeqjVFYVL3"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/LRM37xarSuPJmv92"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/WvT2Q0r9vlJYyMM8"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/CaRFhkrefL4miesE"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/j3HE6cOkCmKbxxAt"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/2luqHy9iADx4UNm7"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/U45AGi5nsDtoDf3u"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/knK4jnD2hIVxQoyk"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/TGvdYyJtstacZxWq"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/kjcoWACW7FMqKRBG"><b>online</b></a>
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
<a target="_blank" href="https://wandbox.org/permlink/BMlas6312rkE4cxz"><b>online</b></a>
 | 
			
		||||
<a target="_blank" href="https://wandbox.org/permlink/0LBIsEa18IrerWwy"><b>online</b></a>
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
				
			
			@ -572,6 +572,13 @@ class json_sax_dom_callback_parser
 | 
			
		|||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            // skip this value if we already decided to skip the parent
 | 
			
		||||
            // (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
 | 
			
		||||
            if (not ref_stack.back())
 | 
			
		||||
            {
 | 
			
		||||
                return {false, nullptr};
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
 | 
			
		||||
            if (ref_stack.back()->is_array())
 | 
			
		||||
            {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4348,6 +4348,13 @@ class json_sax_dom_callback_parser
 | 
			
		|||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            // skip this value if we already decided to skip the parent
 | 
			
		||||
            // (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
 | 
			
		||||
            if (not ref_stack.back())
 | 
			
		||||
            {
 | 
			
		||||
                return {false, nullptr};
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
 | 
			
		||||
            if (ref_stack.back()->is_array())
 | 
			
		||||
            {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1472,6 +1472,46 @@ TEST_CASE("regression tests")
 | 
			
		|||
        //                  "[json.exception.out_of_range.408] excessive object size: 8658170730974374167");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("issue #971 - Add a SAX parser - late bug")
 | 
			
		||||
    {
 | 
			
		||||
        // a JSON text
 | 
			
		||||
        auto text = R"(
 | 
			
		||||
    {
 | 
			
		||||
        "Image": {
 | 
			
		||||
            "Width":  800,
 | 
			
		||||
            "Height": 600,
 | 
			
		||||
            "Title":  "View from 15th Floor",
 | 
			
		||||
            "Thumbnail": {
 | 
			
		||||
                "Url":    "http://www.example.com/image/481989943",
 | 
			
		||||
                "Height": 125,
 | 
			
		||||
                "Width":  100
 | 
			
		||||
            },
 | 
			
		||||
            "Animated" : false,
 | 
			
		||||
            "IDs": [116, 943, 234, 38793]
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    )";
 | 
			
		||||
 | 
			
		||||
        // define parser callback
 | 
			
		||||
        json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
 | 
			
		||||
        {
 | 
			
		||||
            // skip object elements with key "Thumbnail"
 | 
			
		||||
            if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
 | 
			
		||||
            {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        // parse (with callback) and serialize JSON
 | 
			
		||||
        json j_filtered = json::parse(text, cb);
 | 
			
		||||
 | 
			
		||||
        CHECK(j_filtered == R"({"Image":{"Animated":false,"Height":600,"IDs":[116,943,234,38793], "Title":"View from 15th Floor","Width":800}})"_json);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SECTION("issue #972 - Segmentation fault on G++ when trying to assign json string literal to custom json type")
 | 
			
		||||
    {
 | 
			
		||||
        my_json foo = R"([1, 2, 3])"_json;
 | 
			
		||||
| 
						 | 
				
			
			@ -1536,34 +1576,34 @@ TEST_CASE("regression tests")
 | 
			
		|||
            switch (event)
 | 
			
		||||
            {
 | 
			
		||||
                case json::parse_event_t::key:
 | 
			
		||||
                {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
                    {
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                case json::parse_event_t::value:
 | 
			
		||||
                {
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
                    {
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
                case json::parse_event_t::object_start:
 | 
			
		||||
                {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
                    {
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                case json::parse_event_t::object_end:
 | 
			
		||||
                {
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
                    {
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
                case json::parse_event_t::array_start:
 | 
			
		||||
                {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
                    {
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                case json::parse_event_t::array_end:
 | 
			
		||||
                {
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
                    {
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                default:
 | 
			
		||||
                {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
                    {
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue