Skip to content
  • Ed Sharp's avatar
    5b6bc8f5
    Fix hstore deserialize regression · 5b6bc8f5
    Ed Sharp authored
    https://github.com/rails/rails/commit/98bf64bcb9648f88bff4cb59a7ae4db2b6410241
    introduced a StringScanner to ensure that value is a valid hstore
    document.
    
    However, the negative lookbehind in the regex used to find the final
    double-quote of both the key and the value (/(?<!\\)(?=")/) doesn't
    differentiate between a backslash-escaped double-quote and a
    backslash-escaped backslash followed by an unescaped double-quote.
    
    In other words a valid hstore document such as:
    
        postgres=# select '"\\"=>"\\"'::hstore;
           hstore
        ------------
         "\\"=>"\\"
    
    will be incorrectly deemed invalid.
    
    This commit aims to rectify that by switching from scan_until to scan
    and lazily matching zero or more of either:
    
    - an escaped pair (either \\ or \"); or
    
    - a character that doesn't need escaping
    
    until the positive lookahead matches a double-quote.
    
    The tests have been updated to include both a key and value that end in
    a backslash.
    5b6bc8f5
    Fix hstore deserialize regression
    Ed Sharp authored
    https://github.com/rails/rails/commit/98bf64bcb9648f88bff4cb59a7ae4db2b6410241
    introduced a StringScanner to ensure that value is a valid hstore
    document.
    
    However, the negative lookbehind in the regex used to find the final
    double-quote of both the key and the value (/(?<!\\)(?=")/) doesn't
    differentiate between a backslash-escaped double-quote and a
    backslash-escaped backslash followed by an unescaped double-quote.
    
    In other words a valid hstore document such as:
    
        postgres=# select '"\\"=>"\\"'::hstore;
           hstore
        ------------
         "\\"=>"\\"
    
    will be incorrectly deemed invalid.
    
    This commit aims to rectify that by switching from scan_until to scan
    and lazily matching zero or more of either:
    
    - an escaped pair (either \\ or \"); or
    
    - a character that doesn't need escaping
    
    until the positive lookahead matches a double-quote.
    
    The tests have been updated to include both a key and value that end in
    a backslash.
Loading