# HG changeset patch # User Sylvain Thénault # Date 1428349612 -7200 # Node ID d7ff46d958f4cc1701249a891a530fe2fbb293d7 # Parent a504a7840915f05f9b103a97854d62fb30df89c0 [postgres] fix limit_size regexp to properly remove one char tags like

. Closes #5221847 diff -r a504a7840915 -r d7ff46d958f4 misc/migration/3.20.7_Any.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/migration/3.20.7_Any.py Mon Apr 06 21:46:52 2015 +0200 @@ -0,0 +1,2 @@ +if repo.system_source.dbdriver == 'postgres': + install_custom_sql_scripts() diff -r a504a7840915 -r d7ff46d958f4 schemas/_regproc.postgres.sql --- a/schemas/_regproc.postgres.sql Wed Apr 15 22:08:08 2015 +0200 +++ b/schemas/_regproc.postgres.sql Mon Apr 06 21:46:52 2015 +0200 @@ -26,7 +26,6 @@ );; - DROP FUNCTION IF EXISTS limit_size (fulltext text, format text, maxsize integer); CREATE FUNCTION limit_size (fulltext text, format text, maxsize integer) RETURNS text AS $$ DECLARE @@ -36,7 +35,7 @@ RETURN fulltext; END IF; IF format = 'text/html' OR format = 'text/xhtml' OR format = 'text/xml' THEN - plaintext := regexp_replace(fulltext, '<[\\w/][^>]+>', '', 'g'); + plaintext := regexp_replace(fulltext, '<[a-zA-Z/][^>]*>', '', 'g'); ELSE plaintext := fulltext; END IF; diff -r a504a7840915 -r d7ff46d958f4 server/test/unittest_postgres.py --- a/server/test/unittest_postgres.py Wed Apr 15 22:08:08 2015 +0200 +++ b/server/test/unittest_postgres.py Mon Apr 06 21:46:52 2015 +0200 @@ -113,6 +113,24 @@ self.assertEqual(datenaiss.tzinfo, None) self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 2, 0)) +class PostgresLimitSizeTC(CubicWebTC): + configcls = PostgresApptestConfiguration + + def test(self): + with self.admin_access.repo_cnx() as cnx: + def sql(string): + return cnx.system_sql(string).fetchone()[0] + yield self.assertEqual, sql("SELECT limit_size('

hello

', 'text/html', 20)"), \ + '

hello

' + yield self.assertEqual, sql("SELECT limit_size('

hello

', 'text/html', 2)"), \ + 'he...' + yield self.assertEqual, sql("SELECT limit_size('
hello', 'text/html', 2)"), \ + 'he...' + yield self.assertEqual, sql("SELECT limit_size('hello', 'text/html', 2)"), \ + 'he...' + yield self.assertEqual, sql("SELECT limit_size('a>b', 'text/html', 2)"), \ + 'a>...' + if __name__ == '__main__': from logilab.common.testlib import unittest_main unittest_main()