Skip to content

Instantly share code, notes, and snippets.

@kt81
Created February 25, 2015 07:56
Show Gist options
  • Save kt81/36887de8b13ea2dd7047 to your computer and use it in GitHub Desktop.
Save kt81/36887de8b13ea2dd7047 to your computer and use it in GitHub Desktop.
SQLでhtmlspecialchars的な事をしようとしたことの名残
CREATE OR REPLACE FUNCTION orig_htmlspecialchars(TEXT) RETURNS TEXT AS $$
SELECT
regexp_replace(
regexp_replace(
regexp_replace(
regexp_replace(
regexp_replace($1,
E'&(?!(?:#\\d+?|\\w+?);)', '&', 'g'),
E'"', '"', 'g'),
E'''', ''', 'g'),
E'<', '&lt;', 'g'),
E'>', '&gt;', 'g')
$$ LANGUAGE SQL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment