Skip to content

Commit

Permalink
Un/Escaping links, refs #36
Browse files Browse the repository at this point in the history
  • Loading branch information
philipsorst committed Jun 17, 2016
1 parent 0fb44f8 commit c6e3886
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Markdown/Renderer/FileSystemAwareLinkRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Dontdrinkandroot\Path\FilePath;
use Dontdrinkandroot\Utils\StringUtils;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\HtmlElement;
use League\CommonMark\HtmlRendererInterface;
use League\CommonMark\Inline\Element\AbstractInline;
use League\CommonMark\Inline\Element\Link;
Expand Down Expand Up @@ -90,6 +89,9 @@ protected function targetUrlExists($url)
/* Absolute paths won't work */
return false;
}

$urlPath = urldecode($urlPath);

$currentDirectoryPath = $this->currentFilePath->getParentPath();
$path = $currentDirectoryPath->appendPathString($urlPath);
$fileExists = $this->fileSystemService->exists($path);
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Markdown/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
var selection = getSelection();
var path = $('#internal-link-file').val();
var text = $('#internal-link-text').val();
var newMarkDown = selection.before + '[' + text + '](' + path + ')' + selection.after;
var newMarkDown = selection.before + '[' + text + '](' + encodeURI(path) + ')' + selection.after;
$editArea.val(newMarkDown);
$('#internalLinkModal').modal('hide');
$('#external-link-file').val('');
Expand Down
2 changes: 2 additions & 0 deletions Tests/Data/repo/examples/a filename with spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A filename with spaces
======================
5 changes: 5 additions & 0 deletions Tests/Data/repo/examples/link-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ Missing Link
------------

[Missing](./missing.md)

Link with Spaces
----------------

[Link with Spaces](./a%20filename%20with%20spaces.md)
6 changes: 4 additions & 2 deletions Tests/Service/WikiServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ public function testFindAllFiles()
{
/** @var FilePath[] $files */
$files = $this->wikiService->findAllFiles();
$this->assertCount(4, $files);
$this->assertCount(5, $files);

$expectedFilePaths = [
'/examples/a filename with spaces.md',
'/index.md',
'/examples/link-example.md',
'/examples/toc-example.md',
Expand All @@ -71,9 +72,10 @@ public function testFindAllFilesWithPath()
{
/** @var FilePath[] $files */
$files = $this->wikiService->findAllFiles(DirectoryPath::parse('/examples/'));
$this->assertCount(3, $files);
$this->assertCount(4, $files);

$expectedFilePaths = [
'/examples/a filename with spaces.md',
'/examples/link-example.md',
'/examples/toc-example.md',
'/examples/table-example.md'
Expand Down

0 comments on commit c6e3886

Please sign in to comment.