Hi,

On 2022-07-06 12:10:20 +0700, John Naylor wrote:
> diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c
> index eeedc0645a..ad4858c623 100644
> --- a/src/common/jsonapi.c
> +++ b/src/common/jsonapi.c
> @@ -851,10 +851,26 @@ json_lex_string(JsonLexContext *lex)
>               }
>               else if (lex->strval != NULL)
>               {
> +                     /* start lookahead at next byte */
> +                     char       *p = s + 1;
> +
>                       if (hi_surrogate != -1)
>                               return JSON_UNICODE_LOW_SURROGATE;
>  
> -                     appendStringInfoChar(lex->strval, *s);
> +                     while (p < end)
> +                     {
> +                             if (*p == '\\' || *p == '"' || (unsigned char) 
> *p < 32)
> +                                     break;
> +                             p++;
> +                     }
> +
> +                     appendBinaryStringInfo(lex->strval, s, p - s);
> +
> +                     /*
> +                      * s will be incremented at the top of the loop, so set 
> it to just
> +                      * behind our lookahead position
> +                      */
> +                     s = p - 1;
>               }
>       }
>  
> -- 
> 2.36.1

I think before committing something along those lines we should make the
relevant bits also be applicable when ->strval is NULL, as several functions
use that (notably json_in IIRC). Afaics we'd just need to move the strval
check to be around the appendBinaryStringInfo(). And it should simplify the
function, because some of the relevant code is duplicated outside as well...

Greetings,

Andres Freund


Reply via email to