diff options
Diffstat (limited to 'db/rest/util')
-rw-r--r-- | db/rest/util/_api_trim.sql | 25 | ||||
-rw-r--r-- | db/rest/util/_api_validate_text.sql | 2 |
2 files changed, 27 insertions, 0 deletions
diff --git a/db/rest/util/_api_trim.sql b/db/rest/util/_api_trim.sql new file mode 100644 index 0000000..c972282 --- /dev/null +++ b/db/rest/util/_api_trim.sql @@ -0,0 +1,25 @@ +CREATE FUNCTION _api.trim( + _text TEXT +) +RETURNS TEXT +LANGUAGE plpgsql VOLATILE +AS $BODY$ +DECLARE + _new TEXT; +BEGIN + + IF _text IS NULL THEN + RETURN NULL; + END IF; + + _new = _text; + _new = TRIM(_new); + _new = REGEXP_REPLACE(_new, '^(?: |\r|\n)*', ''); + _new = REGEXP_REPLACE(_new, '(?: |\r|\n)*$', ''); + + RETURN _new; +END +$BODY$; + +GRANT EXECUTE ON FUNCTION _api.trim(TEXT) + TO rest_anon, rest_user; diff --git a/db/rest/util/_api_validate_text.sql b/db/rest/util/_api_validate_text.sql index e4a6a7b..ff3a227 100644 --- a/db/rest/util/_api_validate_text.sql +++ b/db/rest/util/_api_validate_text.sql @@ -33,6 +33,7 @@ BEGIN _detail => _column, _hint => _min || '' ); + RETURN FALSE; END IF; IF _max IS NOT NULL AND _length > _max THEN @@ -41,6 +42,7 @@ BEGIN _detail => _column, _hint => _max || '' ); + RETURN FALSE; END IF; RETURN TRUE; |