package com.fasterxml.jackson.failing;

import com.fasterxml.jackson.core.BaseTest;
import com.fasterxml.jackson.core.JsonPointer;

// For https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=51806
// (via databind, but we don't need that)
public class Fuzz51806JsonPointerParseTest extends BaseTest
{
    // Before fix, looks like this is enough to cause StackOverflowError
    private final static int TOO_DEEP_PATH = 6000;

    // Verify that very deep/long (by number of segments) JsonPointer
    // may still be parsed ok
    public void testJsonPointerParseTail() throws Exception
    {
        JsonPointer p = JsonPointer.compile(_generatePath(TOO_DEEP_PATH));
        assertNotNull(p);
    }

    private String _generatePath(int depth) {
        StringBuilder sb = new StringBuilder(4 * depth);
        for (int i = 0; i < depth; ++i) {
            sb.append("/a").append(depth);
        }
        return sb.toString();
    }
}

@@ -200,45 +200,30 @@
 // (
-via databind, but we don't need that)
+reported as %5Bcore#818%5D
 %0Apub
@@ -425,16 +425,18 @@
 fy that 
+a 
 very dee
@@ -507,16 +507,53 @@
 arsed ok
+, for %22simple%22 case (no quoted chars)
 %0A    pub
@@ -589,27 +589,16 @@
 Tail
-() throws Exception
+Simple()
 %0A   
@@ -608,16 +608,21 @@
         
+_test
 JsonPoin
@@ -628,32 +628,137 @@
 nter
- p = JsonPointer.compile
+(_generatePath(TOO_DEEP_PATH, false));%0A    %7D%0A%0A    public void testJsonPointerParseTailWithQuoted()%0A    %7B%0A        _testJsonPointer
 (_ge
@@ -781,24 +781,30 @@
 EEP_PATH
+, true
 ));%0A    
     asse
@@ -799,27 +799,236 @@
     
-    assertNotNull(p
+%7D%0A%0A    private void _testJsonPointer(String pathExpr)%0A    %7B%0A        JsonPointer p = JsonPointer.compile(pathExpr);%0A        assertNotNull(p);%0A        // But also verify it didn't change%0A        assertEquals(pathExpr, p.toString()
 );%0A 
@@ -1075,16 +1075,33 @@
 nt depth
+, boolean escaped
 ) %7B%0A    
@@ -1221,28 +1221,356 @@
 end(
-%22/a%22).append(depth);
+'/')%0A                .append((char) ('a' + i%2525))%0A                .append(i);%0A%0A            if (escaped) %7B%0A                switch (i & 7) %7B%0A                case 1:%0A                    sb.append(%22~0x%22);%0A                    break;%0A                case 4:%0A                    sb.append(%22~1y%22);%0A                    break;%0A                %7D%0A            %7D
 %0A   

Improve #818 test a bit