Skip to content

Commit

Permalink
Fix for non http/s external links - #738
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Apr 11, 2016
1 parent c7c69cb commit 63c2db5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions system/src/Grav/Common/Markdown/ParsedownGravTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Utils;
use RocketTheme\Toolbox\Event\Event;

/**
Expand All @@ -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 = [];
Expand Down Expand Up @@ -93,7 +93,7 @@ public function addInlineType($type, $tag, $index = null)
} else {
array_splice($this->InlineTypes[$type], $index, 0, $tag);
}

if (strpos($this->inlineMarkerList, $type) === false) {
$this->inlineMarkerList .= $type;
}
Expand Down Expand Up @@ -342,7 +342,7 @@ protected function inlineLink($excerpt)
}

// 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;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/Grav/Common/Markdown/ParsedownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ public function testSpecialProtocols()
$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()
Expand All @@ -600,6 +602,8 @@ public function testSpecialProtocolsSubDir()
$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()
Expand All @@ -615,6 +619,8 @@ public function testSpecialProtocolsSubDirAbsoluteUrl()
$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()
Expand Down

0 comments on commit 63c2db5

Please sign in to comment.