You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2026/08/18 08:54:00 UTC

[jira] [Commented] (GROOVY-12272) JsonLexer re-validates the whole prefix per quote

    [ https://issues.apache.org/jira/browse/GROOVY-12272?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18105526#comment-18105526 ] 

ASF GitHub Bot commented on GROOVY-12272:
-----------------------------------------

paulk-asert opened a new pull request, #2809:
URL: https://github.com/apache/groovy/pull/2809

   JsonLexer's string branch appended one character at a time and, at every unescaped quote, re-validated the whole accumulated token by copying it to a String and running two regular expressions over it. For a well formed string the closing quote is the first unescaped one, so that happened once. For a string holding an invalid escape the validation could never succeed, so the loop consumed the rest of the document and paid the cost again at every quote it passed, giving O(n^2) behaviour on input an author controls.
   
   Measured on a document of the shape {"k":"\q" followed by n quotes, parsed with JsonSlurperClassic:
   
     quotes    before     after
      2,000     42 ms      4 ms
      4,000     67 ms      0 ms
      8,000    220 ms      0 ms
     16,000    874 ms      0 ms
   
   Read and check each escape sequence where the backslash is found instead. The scan becomes linear, the accepted language is unchanged, and a bad escape is now reported at its own position rather than after the document has been consumed to its end. Escape-state tracking is no longer needed, since consuming the sequence in place is what distinguishes an escaped quote from a closing one.
   
   Note the reach is wider than the parser: JsonOutput.prettyPrint(String) lexes through the same class, so it shared the behaviour.




> JsonLexer re-validates the whole prefix per quote
> -------------------------------------------------
>
>                 Key: GROOVY-12272
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12272
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)