Skip to content

Funtion `anon.hash` crash for text field containing `\`

Hi!

First and foremost, thanks for this amazing extension!

I am encountering an issue with function anon.hash upon text field containing \ character.

It happens because the text field cannot be converted to bytea, here is a concrete error message:

Error in query: ERROR: invalid input syntax for type bytea
LINE 1: select 'test\data'::bytea

To fix it, I created a new function that replace \ by a double one \\:

CREATE OR REPLACE FUNCTION anon.safe_hash(seed text)
 RETURNS text
 LANGUAGE sql
 STABLE PARALLEL SAFE STRICT SECURITY DEFINER
 SET search_path TO ''
AS $function$
  SELECT anon.hash(replace(seed, '\', '\\'));
$function$

I don't think it's an optimal fix.

Should it be fixed directly in the extension or not?

Edited by Benoit GALATI
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information