Fix for non http/s external links - #738

This commit is contained in:
Andy Miller
2016-04-10 19:26:06 -06:00
parent c7c69cbd66
commit 63c2db5c85
2 changed files with 9 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ namespace Grav\Common\Markdown;
use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Utils;
use RocketTheme\Toolbox\Event\Event;
/**
@@ -22,7 +23,6 @@ trait ParsedownGravTrait
protected $pages_dir;
protected $special_chars;
protected $twig_link_regex = '/\!*\[(?:.*)\]\((\{([\{%#])\s*(.*?)\s*(?:\2|\})\})\)/';
protected $special_protocols = ['xmpp', 'mailto', 'tel', 'sms'];
public $completable_blocks = [];
public $continuable_blocks = [];
@@ -93,7 +93,7 @@ trait ParsedownGravTrait
} else {
array_splice($this->InlineTypes[$type], $index, 0, $tag);
}
if (strpos($this->inlineMarkerList, $type) === false) {
$this->inlineMarkerList .= $type;
}
@@ -342,7 +342,7 @@ trait ParsedownGravTrait
}
// if special scheme, just return
if(isset($url['scheme']) && in_array($url['scheme'], $this->special_protocols)) {
if(isset($url['scheme']) && !Utils::startsWith($url['scheme'], 'http')) {
return $excerpt;
}

View File

@@ -586,6 +586,8 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->parsedown->text('[tel](tel:123-555-12345)'));
$this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
$this->parsedown->text('[sms](sms:123-555-12345)'));
$this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
$this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
}
public function testSpecialProtocolsSubDir()
@@ -600,6 +602,8 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->parsedown->text('[tel](tel:123-555-12345)'));
$this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
$this->parsedown->text('[sms](sms:123-555-12345)'));
$this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
$this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
}
public function testSpecialProtocolsSubDirAbsoluteUrl()
@@ -615,6 +619,8 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->parsedown->text('[tel](tel:123-555-12345)'));
$this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
$this->parsedown->text('[sms](sms:123-555-12345)'));
$this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
$this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
}
public function testReferenceLinks()