diff --git a/NEWS b/NEWS index f6afcfb..3a35455 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +Version 5.0.7 (2018-06-27) +------------------------------------------------------------------------ + +- Fix: Improve handling of page titles that start or end with numbers. + +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + + Version 5.0.6 (2018-06-20) ------------------------------------------------------------------------ diff --git a/extension.json b/extension.json index 0630b6a..0d68200 100644 --- a/extension.json +++ b/extension.json @@ -10,7 +10,7 @@ ], "type": "parserhook", "url": "https://www.mediawiki.org/wiki/Extension:LinkTitles", - "version": "5.0.6", + "version": "5.0.7", "license-name": "GPL-2.0+", "descriptionmsg": "linktitles-desc", "requires": { diff --git a/gh-pages b/gh-pages index 7161033..4850111 160000 --- a/gh-pages +++ b/gh-pages @@ -1 +1 @@ -Subproject commit 7161033535b0a0624b92cc85a116c64229cd05a2 +Subproject commit 48501118d18e30869a8acdd357a6c14772c4c47b diff --git a/includes/Target.php b/includes/Target.php index b152f34..64d7d12 100644 --- a/includes/Target.php +++ b/includes/Target.php @@ -81,8 +81,8 @@ public function __construct( $namespace, $title, Config &$config ) { // to detect whole words containing non-ASCII characters as well. // Note that this requires a PCRE library that was compiled with // --enable-unicode-properties - ( $config->wordStartOnly ) ? $this->wordStart = '(?wordStart = ''; - ( $config->wordEndOnly ) ? $this->wordEnd = '(?!\pL)' : $this->wordEnd = ''; + ( $config->wordStartOnly ) ? $this->wordStart = '(?wordStart = ''; + ( $config->wordEndOnly ) ? $this->wordEnd = '(?!\pL|\pN)' : $this->wordEnd = ''; } /** diff --git a/tests/phpunit/LinkerTest.php b/tests/phpunit/LinkerTest.php index e43f029..6314185 100644 --- a/tests/phpunit/LinkerTest.php +++ b/tests/phpunit/LinkerTest.php @@ -47,6 +47,44 @@ public function addDBData() { parent::addDBDataOnce(); // call parent after adding page to have targets invalidated } + /** + * @dataProvider provideTestTitleWithNumberData + */ + public function testTitleWithNumber( $input, $expectedOutput ) { + $config = new LinkTitles\Config(); + $config->wordStartOnly = true; + $config->wordEndOnly = true; + $this->insertPage( 'numbered-1', 'This page serves as a link target with a numbered title' ); + $this->insertPage( 'numbered-101', 'This page serves as a link target with a numbered title' ); + parent::addDBDataOnce(); // call parent after adding page to have targets invalidated + $source = LinkTitles\Source::createFromTitleAndText( $this->title, $input, $config ); + $linker = new LinkTitles\Linker( $config ); + $result = $linker->linkContent( $source ); + if ( !$result ) { $result = $input; } + $this->assertSame( $expectedOutput, $result ); + } + + public function provideTestTitleWithNumberData() { + return [ + [ + "Page text with numbered-1 in it.", + "Page text with [[numbered-1]] in it.", + ], + [ + "Page text with numbered-101 in it.", + "Page text with [[numbered-101]] in it.", + ], + [ + "Page text with numbered-1010 in it.", + "Page text with numbered-1010 in it.", + ], + [ + "Page text with link target1 in it.", + "Page text with link target1 in it.", + ], + ]; + } + /** * @dataProvider provideLinkContentTemplatesData */ diff --git a/tests/phpunit/TargetTest.php b/tests/phpunit/TargetTest.php index f1d0c79..8b3a282 100644 --- a/tests/phpunit/TargetTest.php +++ b/tests/phpunit/TargetTest.php @@ -37,7 +37,7 @@ public function testTargetWordStartOnly( $enabled, $delimiter ) { public static function provideStartOnly() { return [ - [ true, '(?