merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

pg_uri_escape.sql (1293B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2026 Taler Systems SA
      4 --
      5 -- TALER is free software; you can redistribute it and/or modify it under the
      6 -- terms of the GNU General Public License as published by the Free Software
      7 -- Foundation; either version 3, or (at your option) any later version.
      8 --
      9 -- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11 -- A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 --
     13 -- You should have received a copy of the GNU General Public License along with
     14 -- TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 --
     16 DROP FUNCTION IF EXISTS merchant.uri_escape;
     17 CREATE FUNCTION merchant.uri_escape(
     18   input TEXT
     19 )
     20   RETURNS TEXT
     21   LANGUAGE sql
     22   IMMUTABLE
     23   PARALLEL SAFE
     24 AS $$
     25 SELECT COALESCE(string_agg(
     26   CASE
     27     WHEN chr(get_byte(b, i)) ~ '[A-Za-z0-9._~-]'
     28       THEN chr(get_byte(b, i))
     29     ELSE '%' || lpad(upper(to_hex(get_byte(b, i))), 2, '0')
     30   END,
     31   ''
     32 ), '')
     33 FROM (
     34   SELECT convert_to(input, 'UTF8') AS b
     35 ) s,
     36 generate_series(0, length(b) - 1) AS i;
     37 $$;
     38 COMMENT ON FUNCTION merchant.uri_escape(TEXT)
     39   IS 'Percent-encodes all characters except RFC 3986 unreserved chars: A-Z a-z 0-9 - . _ ~';