Skip to content

Commit

Permalink
Fixed broken link rendering for external links at start of line
Browse files Browse the repository at this point in the history
External links at the start of line like 'www.example.com' were
not rendered as links any more. The issue was introduced with PR #1988.
Fixes #2399.
  • Loading branch information
lpaulsen93 committed Jun 21, 2018
1 parent e954c88 commit 605005e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions _test/tests/inc/parser/parser_links.test.php
Expand Up @@ -144,6 +144,20 @@ function testExternalWWWLink() {
$this->assertEquals(array_map('stripByteIndex',$this->H->calls),$calls);
}

function testExternalWWWLinkStartOfLine() {
// Regression test for issue #2399
$calls = array (
array('document_start',array()),
array('p_open',array()),
array('externallink',array('http://www.google.com', 'www.google.com')),
array('cdata',array(' Bar')),
array('p_close',array()),
array('document_end',array()),
);
$instructions = p_get_instructions("www.google.com Bar");
$this->assertEquals(array_map('stripByteIndex',$instructions),$calls);
}

function testExternalWWWLinkInPath() {
$this->P->addMode('externallink',new Doku_Parser_Mode_ExternalLink());
// See issue #936. Should NOT generate a link!
Expand Down
4 changes: 2 additions & 2 deletions inc/parser/parser.php
Expand Up @@ -955,8 +955,8 @@ function preConnect() {
$this->patterns[] = '\b(?i)'.$scheme.'(?-i)://['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
}

$this->patterns[] = '(?<=\s)(?i)www?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
$this->patterns[] = '(?<=\s)(?i)ftp?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
$this->patterns[] = '(?<!/)\b(?i)www?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
$this->patterns[] = '(?<!/)\b(?i)ftp?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
}

function connectTo($mode) {
Expand Down

0 comments on commit 605005e

Please sign in to comment.