Fix [JACKSON-853]

diff --git a/release-notes/VERSION b/release-notes/VERSION
index 77bbdb2..6c06eed 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -11,6 +11,7 @@
   * [Issue-21]: Improve handling of String hash code collisions for
    symbol tables; exception for degenerate cases (attacks), improvements
    for calculation otherwise
+  * [JACKSON-853]: JsonStringEncoder.quoteAsString() problem with buffer boundary
 
 ------------------------------------------------------------------------
 === History: ===
diff --git a/src/java/org/codehaus/jackson/io/JsonStringEncoder.java b/src/java/org/codehaus/jackson/io/JsonStringEncoder.java
index 92ee847..b0ed0f0 100644
--- a/src/java/org/codehaus/jackson/io/JsonStringEncoder.java
+++ b/src/java/org/codehaus/jackson/io/JsonStringEncoder.java
@@ -138,8 +138,8 @@
                 }
                 outputBuffer = textBuffer.finishCurrentSegment();
                 int second = length - first;
-                System.arraycopy(_quoteBuffer, first, outputBuffer, outPtr, second);
-                outPtr += second;
+                System.arraycopy(_quoteBuffer, first, outputBuffer, 0, second);
+                outPtr = second;
             } else {
                 System.arraycopy(_quoteBuffer, 0, outputBuffer, outPtr, length);
                 outPtr += length;
diff --git a/src/test/org/codehaus/jackson/io/TestJsonStringEncoder.java b/src/test/org/codehaus/jackson/io/TestJsonStringEncoder.java
index 8ca2e59..14670d3 100644
--- a/src/test/org/codehaus/jackson/io/TestJsonStringEncoder.java
+++ b/src/test/org/codehaus/jackson/io/TestJsonStringEncoder.java
@@ -19,6 +19,24 @@
         assertArrayEquals("\\\"x\\\"".toCharArray(), result);
     }
 
+    // For [JACKSON-853]
+    public void testQuoteLongAsString() throws Exception
+    {
+        JsonStringEncoder encoder = new JsonStringEncoder();
+        StringBuilder sb = new StringBuilder();
+        StringBuilder sb2 = new StringBuilder();
+        for (int i = 0; i < 1111; ++i) {
+            sb.append('"');
+            sb2.append("\\\"");
+        }
+        String input = sb.toString();
+        String exp = sb2.toString();
+        char[] result = encoder.quoteAsString(input);
+        assertEquals(2*input.length(), result.length);
+        assertEquals(exp, new String(result));
+        
+    }
+    
     public void testQuoteAsUTF8() throws Exception
     {
         // In this case, let's actually use existing JsonGenerator to produce expected values