From f3cdc7f272e409d391979d3e6c58dd63573530c0 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 24 Aug 2009 15:46:12 -0400 Subject: Add unit test directory and first test --- tests/URLDetectionTest.php | 189 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 tests/URLDetectionTest.php (limited to 'tests') diff --git a/tests/URLDetectionTest.php b/tests/URLDetectionTest.php new file mode 100644 index 000000000..f35b03eaf --- /dev/null +++ b/tests/URLDetectionTest.php @@ -0,0 +1,189 @@ +assertEquals($expected, $rendered); + } + + static public function provider() + { + return array( + array('example', + 'example'), + array('http://example', + 'http://example'), + array('http://example/', + 'http://example/'), + array('http://example/path', + 'http://example/path'), + array('http://example.com', + 'http://example.com'), + array('https://example.com', + 'https://example.com'), + array('ftp://example.com', + 'ftp://example.com'), + array('ftps://example.com', + 'ftps://example.com'), + array('http://user@example.com', + 'http://user@example.com'), + array('http://user:pass@example.com', + 'http://user:pass@example.com'), + array('http://example.com:8080', + 'http://example.com:8080'), + array('http://www.example.com', + 'http://www.example.com'), + array('http://example.com/', + 'http://example.com/'), + array('http://example.com/path', + 'http://example.com/path'), + array('http://example.com/path.html', + 'http://example.com/path.html'), + array('http://example.com/path.html#fragment', + 'http://example.com/path.html#fragment'), + array('http://example.com/path.php?foo=bar&bar=foo', + 'http://example.com/path.php?foo=bar&bar=foo'), + array('http://müllärör.de', + 'http://müllärör.de'), + array('http://ﺱﺲﺷ.com', + 'http://ﺱﺲﺷ.com'), + array('http://сделаткартинки.com', + 'http://сделаткартинки.com'), + array('http://tūdaliņ.lv', + 'http://tūdaliņ.lv'), + array('http://brændendekærlighed.com', + 'http://brændendekærlighed.com'), + array('http://あーるいん.com', + 'http://あーるいん.com'), + array('http://예비교사.com', + 'http://예비교사.com'), + array('http://example.com.', + 'http://example.com.'), + array('http://example.com?', + 'http://example.com?'), + array('http://example.com!', + 'http://example.com!'), + array('http://example.com,', + 'http://example.com,'), + array('http://example.com;', + 'http://example.com;'), + array('http://example.com:', + 'http://example.com:'), + array('\'http://example.com\'', + '\'http://example.com\''), + array('"http://example.com"', + '"http://example.com"'), + array('http://example.com ', + 'http://example.com'), + array('(http://example.com)', + '(http://example.com)'), + array('[http://example.com]', + '[http://example.com]'), + array('', + '<http://example.com>'), + array('http://example.com/path/(foo)/bar', + 'http://example.com/path/(foo)/bar'), + array('http://example.com/path/[foo]/bar', + 'http://example.com/path/[foo]/bar'), + array('http://example.com/path/foo/(bar)', + 'http://example.com/path/foo/(bar)'), + array('http://example.com/path/foo/[bar]', + 'http://example.com/path/foo/[bar]'), + array('Hey, check out my cool site http://example.com okay?', + 'Hey, check out my cool site http://example.com okay?'), + array('What about parens (e.g. http://example.com/path/foo/(bar))?', + 'What about parens (e.g. http://example.com/path/foo/(bar))?'), + array('What about parens (e.g. http://example.com/path/foo/(bar)?', + 'What about parens (e.g. http://example.com/path/foo/(bar)?'), + array('What about parens (e.g. http://example.com/path/foo/(bar).)?', + 'What about parens (e.g. http://example.com/path/foo/(bar).)?'), + array('What about parens (e.g. http://example.com/path/(foo,bar)?', + 'What about parens (e.g. http://example.com/path/(foo,bar)?'), + array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?', + 'Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?'), + array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?', + 'Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?'), + array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?', + 'Unbalanced too (e.g. http://example.com/path/foo/((((bar)?'), + array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?', + 'Unbalanced too (e.g. http://example.com/path/foo/(bar))))?'), + array('example.com', + 'example.com'), + array('example.org', + 'example.org'), + array('example.co.uk', + 'example.co.uk'), + array('www.example.co.uk', + 'www.example.co.uk'), + array('farm1.images.example.co.uk', + 'farm1.images.example.co.uk'), + array('example.museum', + 'example.museum'), + array('example.travel', + 'example.travel'), + array('example.com.', + 'example.com.'), + array('example.com?', + 'example.com?'), + array('example.com!', + 'example.com!'), + array('example.com,', + 'example.com,'), + array('example.com;', + 'example.com;'), + array('example.com:', + 'example.com:'), + array('\'example.com\'', + '\'example.com\''), + array('"example.com"', + '"example.com"'), + array('example.com ', + 'example.com'), + array('(example.com)', + '(example.com)'), + array('[example.com]', + '[example.com]'), + array('', + '<example.com>'), + array('Hey, check out my cool site example.com okay?', + 'Hey, check out my cool site example.com okay?'), + array('Hey, check out my cool site example.com.I made it.', + 'Hey, check out my cool site example.com.I made it.'), + array('Hey, check out my cool site example.com.Funny thing...', + 'Hey, check out my cool site example.com.Funny thing...'), + array('Hey, check out my cool site example.com.You will love it.', + 'Hey, check out my cool site example.com.You will love it.'), + array('What about parens (e.g. example.com/path/foo/(bar))?', + 'What about parens (e.g. example.com/path/foo/(bar))?'), + array('What about parens (e.g. example.com/path/foo/(bar)?', + 'What about parens (e.g. example.com/path/foo/(bar)?'), + array('What about parens (e.g. example.com/path/foo/(bar).)?', + 'What about parens (e.g. example.com/path/foo/(bar).)?'), + array('What about parens (e.g. example.com/path/(foo,bar)?', + 'What about parens (e.g. example.com/path/(foo,bar)?'), + array('file.ext', + 'file.ext'), + array('file.html', + 'file.html'), + array('file.php', + 'file.php') + ); + } +} + -- cgit v1.2.3-54-g00ecf From add42759c9ae1e8d765fa2098bd12ff8ba4d4eea Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 24 Aug 2009 17:48:24 -0400 Subject: change class to rel in unit tests for URL check --- tests/URLDetectionTest.php | 144 ++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'tests') diff --git a/tests/URLDetectionTest.php b/tests/URLDetectionTest.php index f35b03eaf..ed29dc88e 100644 --- a/tests/URLDetectionTest.php +++ b/tests/URLDetectionTest.php @@ -34,149 +34,149 @@ class URLDetectionTest extends PHPUnit_Framework_TestCase array('http://example/path', 'http://example/path'), array('http://example.com', - 'http://example.com'), + 'http://example.com'), array('https://example.com', - 'https://example.com'), + 'https://example.com'), array('ftp://example.com', - 'ftp://example.com'), + 'ftp://example.com'), array('ftps://example.com', - 'ftps://example.com'), + 'ftps://example.com'), array('http://user@example.com', - 'http://user@example.com'), + 'http://user@example.com'), array('http://user:pass@example.com', - 'http://user:pass@example.com'), + 'http://user:pass@example.com'), array('http://example.com:8080', - 'http://example.com:8080'), + 'http://example.com:8080'), array('http://www.example.com', - 'http://www.example.com'), + 'http://www.example.com'), array('http://example.com/', - 'http://example.com/'), + 'http://example.com/'), array('http://example.com/path', - 'http://example.com/path'), + 'http://example.com/path'), array('http://example.com/path.html', - 'http://example.com/path.html'), + 'http://example.com/path.html'), array('http://example.com/path.html#fragment', - 'http://example.com/path.html#fragment'), + 'http://example.com/path.html#fragment'), array('http://example.com/path.php?foo=bar&bar=foo', - 'http://example.com/path.php?foo=bar&bar=foo'), + 'http://example.com/path.php?foo=bar&bar=foo'), array('http://müllärör.de', - 'http://müllärör.de'), + 'http://müllärör.de'), array('http://ﺱﺲﺷ.com', - 'http://ﺱﺲﺷ.com'), + 'http://ﺱﺲﺷ.com'), array('http://сделаткартинки.com', - 'http://сделаткартинки.com'), + 'http://сделаткартинки.com'), array('http://tūdaliņ.lv', - 'http://tūdaliņ.lv'), + 'http://tūdaliņ.lv'), array('http://brændendekærlighed.com', - 'http://brændendekærlighed.com'), + 'http://brændendekærlighed.com'), array('http://あーるいん.com', - 'http://あーるいん.com'), + 'http://あーるいん.com'), array('http://예비교사.com', - 'http://예비교사.com'), + 'http://예비교사.com'), array('http://example.com.', - 'http://example.com.'), + 'http://example.com.'), array('http://example.com?', - 'http://example.com?'), + 'http://example.com?'), array('http://example.com!', - 'http://example.com!'), + 'http://example.com!'), array('http://example.com,', - 'http://example.com,'), + 'http://example.com,'), array('http://example.com;', - 'http://example.com;'), + 'http://example.com;'), array('http://example.com:', - 'http://example.com:'), + 'http://example.com:'), array('\'http://example.com\'', - '\'http://example.com\''), + '\'http://example.com\''), array('"http://example.com"', - '"http://example.com"'), + '"http://example.com"'), array('http://example.com ', - 'http://example.com'), + 'http://example.com'), array('(http://example.com)', - '(http://example.com)'), + '(http://example.com)'), array('[http://example.com]', - '[http://example.com]'), + '[http://example.com]'), array('', - '<http://example.com>'), + '<http://example.com>'), array('http://example.com/path/(foo)/bar', - 'http://example.com/path/(foo)/bar'), + 'http://example.com/path/(foo)/bar'), array('http://example.com/path/[foo]/bar', - 'http://example.com/path/[foo]/bar'), + 'http://example.com/path/[foo]/bar'), array('http://example.com/path/foo/(bar)', - 'http://example.com/path/foo/(bar)'), + 'http://example.com/path/foo/(bar)'), array('http://example.com/path/foo/[bar]', - 'http://example.com/path/foo/[bar]'), + 'http://example.com/path/foo/[bar]'), array('Hey, check out my cool site http://example.com okay?', - 'Hey, check out my cool site http://example.com okay?'), + 'Hey, check out my cool site http://example.com okay?'), array('What about parens (e.g. http://example.com/path/foo/(bar))?', - 'What about parens (e.g. http://example.com/path/foo/(bar))?'), + 'What about parens (e.g. http://example.com/path/foo/(bar))?'), array('What about parens (e.g. http://example.com/path/foo/(bar)?', - 'What about parens (e.g. http://example.com/path/foo/(bar)?'), + 'What about parens (e.g. http://example.com/path/foo/(bar)?'), array('What about parens (e.g. http://example.com/path/foo/(bar).)?', - 'What about parens (e.g. http://example.com/path/foo/(bar).)?'), + 'What about parens (e.g. http://example.com/path/foo/(bar).)?'), array('What about parens (e.g. http://example.com/path/(foo,bar)?', - 'What about parens (e.g. http://example.com/path/(foo,bar)?'), + 'What about parens (e.g. http://example.com/path/(foo,bar)?'), array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?', - 'Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?'), + 'Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?'), array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?', - 'Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?'), + 'Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?'), array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?', - 'Unbalanced too (e.g. http://example.com/path/foo/((((bar)?'), + 'Unbalanced too (e.g. http://example.com/path/foo/((((bar)?'), array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?', - 'Unbalanced too (e.g. http://example.com/path/foo/(bar))))?'), + 'Unbalanced too (e.g. http://example.com/path/foo/(bar))))?'), array('example.com', - 'example.com'), + 'example.com'), array('example.org', - 'example.org'), + 'example.org'), array('example.co.uk', - 'example.co.uk'), + 'example.co.uk'), array('www.example.co.uk', - 'www.example.co.uk'), + 'www.example.co.uk'), array('farm1.images.example.co.uk', - 'farm1.images.example.co.uk'), + 'farm1.images.example.co.uk'), array('example.museum', - 'example.museum'), + 'example.museum'), array('example.travel', - 'example.travel'), + 'example.travel'), array('example.com.', - 'example.com.'), + 'example.com.'), array('example.com?', - 'example.com?'), + 'example.com?'), array('example.com!', - 'example.com!'), + 'example.com!'), array('example.com,', - 'example.com,'), + 'example.com,'), array('example.com;', - 'example.com;'), + 'example.com;'), array('example.com:', - 'example.com:'), + 'example.com:'), array('\'example.com\'', - '\'example.com\''), + '\'example.com\''), array('"example.com"', - '"example.com"'), + '"example.com"'), array('example.com ', - 'example.com'), + 'example.com'), array('(example.com)', - '(example.com)'), + '(example.com)'), array('[example.com]', - '[example.com]'), + '[example.com]'), array('', - '<example.com>'), + '<example.com>'), array('Hey, check out my cool site example.com okay?', - 'Hey, check out my cool site example.com okay?'), + 'Hey, check out my cool site example.com okay?'), array('Hey, check out my cool site example.com.I made it.', - 'Hey, check out my cool site example.com.I made it.'), + 'Hey, check out my cool site example.com.I made it.'), array('Hey, check out my cool site example.com.Funny thing...', - 'Hey, check out my cool site example.com.Funny thing...'), + 'Hey, check out my cool site example.com.Funny thing...'), array('Hey, check out my cool site example.com.You will love it.', - 'Hey, check out my cool site example.com.You will love it.'), + 'Hey, check out my cool site example.com.You will love it.'), array('What about parens (e.g. example.com/path/foo/(bar))?', - 'What about parens (e.g. example.com/path/foo/(bar))?'), + 'What about parens (e.g. example.com/path/foo/(bar))?'), array('What about parens (e.g. example.com/path/foo/(bar)?', - 'What about parens (e.g. example.com/path/foo/(bar)?'), + 'What about parens (e.g. example.com/path/foo/(bar)?'), array('What about parens (e.g. example.com/path/foo/(bar).)?', - 'What about parens (e.g. example.com/path/foo/(bar).)?'), + 'What about parens (e.g. example.com/path/foo/(bar).)?'), array('What about parens (e.g. example.com/path/(foo,bar)?', - 'What about parens (e.g. example.com/path/(foo,bar)?'), + 'What about parens (e.g. example.com/path/(foo,bar)?'), array('file.ext', 'file.ext'), array('file.html', -- cgit v1.2.3-54-g00ecf From 9fd3a41576bd5365f9156b47490eecddfb2aa842 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Mon, 24 Aug 2009 20:44:06 -0400 Subject: ftps protocol should be handled the same way as ftp Canon urls that have a protocol followed by a host (and no path) automatcally get a trailing slash by the canon function - make the unit test match that --- classes/File_redirection.php | 2 +- tests/URLDetectionTest.php | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/classes/File_redirection.php b/classes/File_redirection.php index d6fa0bcb6..363e3b947 100644 --- a/classes/File_redirection.php +++ b/classes/File_redirection.php @@ -182,7 +182,7 @@ class File_redirection extends Memcached_DataObject } } - if (('ftp' == $p['scheme']) || ('http' == $p['scheme']) || ('https' == $p['scheme'])) { + if (('ftp' == $p['scheme']) || ('ftps' == $p['scheme']) || ('http' == $p['scheme']) || ('https' == $p['scheme'])) { if (empty($p['host'])) return false; if (empty($p['path'])) { $out_url .= '/'; diff --git a/tests/URLDetectionTest.php b/tests/URLDetectionTest.php index ed29dc88e..e69f1a2c3 100644 --- a/tests/URLDetectionTest.php +++ b/tests/URLDetectionTest.php @@ -28,27 +28,27 @@ class URLDetectionTest extends PHPUnit_Framework_TestCase array('example', 'example'), array('http://example', - 'http://example'), + 'http://example'), array('http://example/', - 'http://example/'), + 'http://example/'), array('http://example/path', - 'http://example/path'), + 'http://example/path'), array('http://example.com', - 'http://example.com'), + 'http://example.com'), array('https://example.com', - 'https://example.com'), + 'https://example.com'), array('ftp://example.com', - 'ftp://example.com'), + 'ftp://example.com'), array('ftps://example.com', - 'ftps://example.com'), + 'ftps://example.com'), array('http://user@example.com', - 'http://user@example.com'), + 'http://user@example.com'), array('http://user:pass@example.com', - 'http://user:pass@example.com'), + 'http://user:pass@example.com'), array('http://example.com:8080', - 'http://example.com:8080'), + 'http://example.com:8080'), array('http://www.example.com', - 'http://www.example.com'), + 'http://www.example.com'), array('http://example.com/', 'http://example.com/'), array('http://example.com/path', @@ -58,7 +58,7 @@ class URLDetectionTest extends PHPUnit_Framework_TestCase array('http://example.com/path.html#fragment', 'http://example.com/path.html#fragment'), array('http://example.com/path.php?foo=bar&bar=foo', - 'http://example.com/path.php?foo=bar&bar=foo'), + 'http://example.com/path.php?foo=bar&bar=foo'), array('http://müllärör.de', 'http://müllärör.de'), array('http://ﺱﺲﺷ.com', -- cgit v1.2.3-54-g00ecf From 3ff67b3bc185be255d0b54f7f9af7c9578b4330b Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 25 Aug 2009 10:33:16 +1200 Subject: beginning of hashtag tests --- tests/HashTagDetectionTest.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/HashTagDetectionTest.php (limited to 'tests') diff --git a/tests/HashTagDetectionTest.php b/tests/HashTagDetectionTest.php new file mode 100644 index 000000000..71137b0b5 --- /dev/null +++ b/tests/HashTagDetectionTest.php @@ -0,0 +1,35 @@ +assertEquals($expected, $rendered); + } + + static public function provider() + { + return array( + array('hello', + 'hello'), + array('#hello', + 'hello'), + ); + } +} + -- cgit v1.2.3-54-g00ecf From 6a3a25b5a2b65e54841cc60c4f2254f6d7b6b54b Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 25 Aug 2009 11:21:45 -0400 Subject: Improved the URL tests, and improve the matcher so more tests are passed. The remaining failing tests I believe are incorrect. --- lib/util.php | 24 ++++---- tests/URLDetectionTest.php | 143 ++++++++++++++++++++++++++++++--------------- 2 files changed, 110 insertions(+), 57 deletions(-) (limited to 'tests') diff --git a/lib/util.php b/lib/util.php index 2be4213e7..ee3fe5ddc 100644 --- a/lib/util.php +++ b/lib/util.php @@ -412,30 +412,34 @@ function common_render_text($text) function common_replace_urls_callback($text, $callback, $notice_id = null) { // Start off with a regex $regex = '#'. - '(?:^|[\s\(\)\[\]\{\}]+)'. - '('. + '(?:^|[\s\(\)\[\]\{\}\\\'\\\";]+)(?![\@\!\#])'. + '('. '(?:'. '(?:'. //Known protocols '(?:'. '(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://'. '|'. '(?:mailto|aim|tel|xmpp):'. - ')[^\s\/]+'. + ')'. + '(?:[\pN\pL\-\_\+]+(?:\:[\pN\pL\-\_\+]+)?\@)?'. //user:pass@ + '[\pN\pL\-\_\:\.]+(?127.0.0.1'), + array('127.0.0.1/test.php', + '127.0.0.1/test.php'), + array('http://::1/test.php', + 'http://::1/test.php'), + array('http://::1', + 'http://::1'), + array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php', + '2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php'), + array('2001:4978:1b5:0:21d:e0ff:fe66:59ab', + '2001:4978:1b5:0:21d:e0ff:fe66:59ab'), + array('http://127.0.0.1', + 'http://127.0.0.1'), + array('example.com', + 'example.com'), + array('example.com', + 'example.com'), + array('http://example.com', + 'http://example.com'), + array('http://example.com.', + 'http://example.com.'), + array('/var/lib/example.so', + '/var/lib/example.so'), array('example', 'example'), + array('user@example.com', + 'user@example.com'), + array('user_name+other@example.com', + 'user_name+other@example.com'), + array('mailto:user@example.com', + 'mailto:user@example.com'), + array('mailto:user@example.com?subject=test', + 'mailto:user@example.com?subject=test'), + array('#example', + '#'), + array('#example.com', + '#'), + array('#.net', + '#'), array('http://example', 'http://example'), + array('http://3xampl3', + 'http://3xampl3'), array('http://example/', 'http://example/'), array('http://example/path', @@ -47,6 +87,10 @@ class URLDetectionTest extends PHPUnit_Framework_TestCase 'http://user:pass@example.com'), array('http://example.com:8080', 'http://example.com:8080'), + array('http://example.com:8080/test.php', + 'http://example.com:8080/test.php'), + array('example.com:8080/test.php', + 'example.com:8080/test.php'), array('http://www.example.com', 'http://www.example.com'), array('http://example.com/', @@ -59,60 +103,65 @@ class URLDetectionTest extends PHPUnit_Framework_TestCase 'http://example.com/path.html#fragment'), array('http://example.com/path.php?foo=bar&bar=foo', 'http://example.com/path.php?foo=bar&bar=foo'), + array('http://example.com.', + 'http://example.com.'), array('http://müllärör.de', - 'http://müllärör.de'), + 'http://müllärör.de'), array('http://ﺱﺲﺷ.com', - 'http://ﺱﺲﺷ.com'), + 'http://ﺱﺲﺷ.com'), array('http://сделаткартинки.com', - 'http://сделаткартинки.com'), + 'http://сделаткартинки.com'), array('http://tūdaliņ.lv', - 'http://tūdaliņ.lv'), + 'http://tūdaliņ.lv'), array('http://brændendekærlighed.com', - 'http://brændendekærlighed.com'), + 'http://brændendekærlighed.com'), array('http://あーるいん.com', - 'http://あーるいん.com'), + 'http://あーるいん.com'), array('http://예비교사.com', - 'http://예비교사.com'), + 'http://예비교사.com'), array('http://example.com.', - 'http://example.com.'), + 'http://example.com.'), array('http://example.com?', - 'http://example.com?'), + 'http://example.com?'), array('http://example.com!', - 'http://example.com!'), + 'http://example.com!'), array('http://example.com,', - 'http://example.com,'), + 'http://example.com,'), array('http://example.com;', - 'http://example.com;'), + 'http://example.com;'), array('http://example.com:', - 'http://example.com:'), + 'http://example.com:'), array('\'http://example.com\'', - '\'http://example.com\''), + '\'http://example.com\''), array('"http://example.com"', - '"http://example.com"'), - array('http://example.com ', - 'http://example.com'), + '"http://example.com"'), + array('http://example.com', + 'http://example.com'), array('(http://example.com)', - '(http://example.com)'), + '(http://example.com)'), array('[http://example.com]', - '[http://example.com]'), + '[http://example.com]'), array('', - '<http://example.com>'), + '<http://example.com>'), array('http://example.com/path/(foo)/bar', 'http://example.com/path/(foo)/bar'), + //Not a valid url - urls cannot contain unencoded square brackets array('http://example.com/path/[foo]/bar', 'http://example.com/path/[foo]/bar'), array('http://example.com/path/foo/(bar)', 'http://example.com/path/foo/(bar)'), - array('http://example.com/path/foo/[bar]', - 'http://example.com/path/foo/[bar]'), + //Not a valid url - urls cannot contain unencoded square brackets + //array('http://example.com/path/foo/[bar]', + // 'http://example.com/path/foo/[bar]'), array('Hey, check out my cool site http://example.com okay?', - 'Hey, check out my cool site http://example.com okay?'), + 'Hey, check out my cool site http://example.com okay?'), array('What about parens (e.g. http://example.com/path/foo/(bar))?', 'What about parens (e.g. http://example.com/path/foo/(bar))?'), array('What about parens (e.g. http://example.com/path/foo/(bar)?', 'What about parens (e.g. http://example.com/path/foo/(bar)?'), array('What about parens (e.g. http://example.com/path/foo/(bar).)?', 'What about parens (e.g. http://example.com/path/foo/(bar).)?'), + //Not a valid url - urls cannot contain unencoded commas array('What about parens (e.g. http://example.com/path/(foo,bar)?', 'What about parens (e.g. http://example.com/path/(foo,bar)?'), array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?', @@ -124,51 +173,51 @@ class URLDetectionTest extends PHPUnit_Framework_TestCase array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?', 'Unbalanced too (e.g. http://example.com/path/foo/(bar))))?'), array('example.com', - 'example.com'), + 'example.com'), array('example.org', - 'example.org'), + 'example.org'), array('example.co.uk', - 'example.co.uk'), + 'example.co.uk'), array('www.example.co.uk', - 'www.example.co.uk'), + 'www.example.co.uk'), array('farm1.images.example.co.uk', - 'farm1.images.example.co.uk'), + 'farm1.images.example.co.uk'), array('example.museum', - 'example.museum'), + 'example.museum'), array('example.travel', - 'example.travel'), + 'example.travel'), array('example.com.', - 'example.com.'), + 'example.com.'), array('example.com?', - 'example.com?'), + 'example.com?'), array('example.com!', - 'example.com!'), + 'example.com!'), array('example.com,', - 'example.com,'), + 'example.com,'), array('example.com;', - 'example.com;'), + 'example.com;'), array('example.com:', - 'example.com:'), + 'example.com:'), array('\'example.com\'', - '\'example.com\''), + '\'example.com\''), array('"example.com"', - '"example.com"'), - array('example.com ', - 'example.com'), + '"example.com"'), + array('example.com', + 'example.com'), array('(example.com)', - '(example.com)'), + '(example.com)'), array('[example.com]', - '[example.com]'), + '[example.com]'), array('', - '<example.com>'), + '<example.com>'), array('Hey, check out my cool site example.com okay?', - 'Hey, check out my cool site example.com okay?'), + 'Hey, check out my cool site example.com okay?'), array('Hey, check out my cool site example.com.I made it.', - 'Hey, check out my cool site example.com.I made it.'), + 'Hey, check out my cool site example.com.I made it.'), array('Hey, check out my cool site example.com.Funny thing...', - 'Hey, check out my cool site example.com.Funny thing...'), + 'Hey, check out my cool site example.com.Funny thing...'), array('Hey, check out my cool site example.com.You will love it.', - 'Hey, check out my cool site example.com.You will love it.'), + 'Hey, check out my cool site example.com.You will love it.'), array('What about parens (e.g. example.com/path/foo/(bar))?', 'What about parens (e.g. example.com/path/foo/(bar))?'), array('What about parens (e.g. example.com/path/foo/(bar)?', -- cgit v1.2.3-54-g00ecf From 210bc4248b5e0c8bd577ac51c2f8df9ac05166ae Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 25 Aug 2009 14:12:31 -0400 Subject: All tests pass except for those that require matching parens or brackets --- lib/util.php | 40 +++++++++++++++++++++++++--------------- tests/URLDetectionTest.php | 13 ++++++++++--- 2 files changed, 35 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/lib/util.php b/lib/util.php index ee3fe5ddc..36d1e4c0a 100644 --- a/lib/util.php +++ b/lib/util.php @@ -413,45 +413,55 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) { // Start off with a regex $regex = '#'. '(?:^|[\s\(\)\[\]\{\}\\\'\\\";]+)(?![\@\!\#])'. - '('. + '(?P'. '(?:'. '(?:'. //Known protocols '(?:'. - '(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://'. + '(?:(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://)'. '|'. - '(?:mailto|aim|tel|xmpp):'. + '(?:(?:mailto|aim|tel|xmpp):)'. + ')'. + '(?:[\pN\pL\-\_\+]+(?::[\pN\pL\-\_\+]+)?\@)?'. //user:pass@ + '(?:'. + '(?:'. + '\[[\pN\pL\-\_\:\.]+(?http://127.0.0.1'), array('127.0.0.1', '127.0.0.1'), + array('127.0.0.1:99', + '127.0.0.1:99'), array('127.0.0.1/test.php', '127.0.0.1/test.php'), + array('http://[::1]:99/test.php', + 'http://[::1]:99/test.php'), array('http://::1/test.php', 'http://::1/test.php'), array('http://::1', 'http://::1'), array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php', '2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php'), + array('[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php', + '[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php'), array('2001:4978:1b5:0:21d:e0ff:fe66:59ab', '2001:4978:1b5:0:21d:e0ff:fe66:59ab'), array('http://127.0.0.1', @@ -145,14 +153,13 @@ class URLDetectionTest extends PHPUnit_Framework_TestCase '<http://example.com>'), array('http://example.com/path/(foo)/bar', 'http://example.com/path/(foo)/bar'), - //Not a valid url - urls cannot contain unencoded square brackets array('http://example.com/path/[foo]/bar', 'http://example.com/path/[foo]/bar'), array('http://example.com/path/foo/(bar)', 'http://example.com/path/foo/(bar)'), //Not a valid url - urls cannot contain unencoded square brackets - //array('http://example.com/path/foo/[bar]', - // 'http://example.com/path/foo/[bar]'), + array('http://example.com/path/foo/[bar]', + 'http://example.com/path/foo/[bar]'), array('Hey, check out my cool site http://example.com okay?', 'Hey, check out my cool site http://example.com okay?'), array('What about parens (e.g. http://example.com/path/foo/(bar))?', -- cgit v1.2.3-54-g00ecf From 8cd474e985fcce754f435b8b8fa84c33a9d623e7 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 25 Aug 2009 16:06:04 -0400 Subject: Correct the hash tag test --- tests/HashTagDetectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/HashTagDetectionTest.php b/tests/HashTagDetectionTest.php index 71137b0b5..55e1f65bf 100644 --- a/tests/HashTagDetectionTest.php +++ b/tests/HashTagDetectionTest.php @@ -28,7 +28,7 @@ class HashTagDetectionTest extends PHPUnit_Framework_TestCase array('hello', 'hello'), array('#hello', - 'hello'), + '#'), ); } } -- cgit v1.2.3-54-g00ecf From a2117961be463d566c8f3c6ccd9b8e840f171804 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 25 Aug 2009 17:52:16 -0400 Subject: Allow ({['" to preceded #tags --- lib/util.php | 2 +- tests/HashTagDetectionTest.php | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/lib/util.php b/lib/util.php index 29eb6cbbc..7c1e21913 100644 --- a/lib/util.php +++ b/lib/util.php @@ -404,7 +404,7 @@ function common_render_text($text) $r = preg_replace('/[\x{0}-\x{8}\x{b}-\x{c}\x{e}-\x{19}]/', '', $r); $r = common_replace_urls_callback($r, 'common_linkify'); - $r = preg_replace('/(^|\(|\[|\s+)#([\pL\pN_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r); + $r = preg_replace('/(^|\"\;|\'|\(|\[|\{|\s+)#([\pL\pN_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r); // XXX: machine tags return $r; } diff --git a/tests/HashTagDetectionTest.php b/tests/HashTagDetectionTest.php index 55e1f65bf..901e0611c 100644 --- a/tests/HashTagDetectionTest.php +++ b/tests/HashTagDetectionTest.php @@ -27,8 +27,20 @@ class HashTagDetectionTest extends PHPUnit_Framework_TestCase return array( array('hello', 'hello'), - array('#hello', - '#'), + array('#hello people', + '# people'), + array('"#hello" people', + '"#" people'), + array('say "#hello" people', + 'say "#" people'), + array('say (#hello) people', + 'say (#) people'), + array('say [#hello] people', + 'say [#] people'), + array('say {#hello} people', + 'say {#} people'), + array('say \'#hello\' people', + 'say \'#\' people'), ); } } -- cgit v1.2.3-54-g00ecf