Skip to content

Commit

Permalink
Merge pull request #7 from ARCANEDEV/patch-1
Browse files Browse the repository at this point in the history
Updating the package
  • Loading branch information
arcanedev-maroc authored Apr 21, 2019
2 parents 7b17a53 + 9afd128 commit 7f258af
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 2
runs: 4
php_code_sniffer:
enabled: true
config:
Expand Down
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
language: php

sudo: false

php:
- 7.0
- 7.1
- 7.2
- 7.3
- nightly

matrix:
allow_failures:
- php: nightly

env:
- TESTBENCH_VERSION=3.5.*

before_script:
- travis_retry composer self-update
- travis_retry composer require --prefer-source --no-interaction --dev "orchestra/testbench:${TESTBENCH_VERSION}"
- travis_retry composer install --prefer-source --no-interaction

script:
- composer validate
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2017 | ARCANEDEV <[email protected]> - LaravelMarkdown
Copyright (c) 2016-2019 | ARCANEDEV <[email protected]> - LaravelMarkdown

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
"license": "MIT",
"require": {
"php": ">=7.0",
"arcanedev/support": "~4.0",
"arcanedev/support": "~4.2.0",
"erusev/parsedown": "~1.6"
},
"require-dev": {
"phpunit/phpunit": "~6.0",
"phpunit/phpcov": "~4.0"
"orchestra/testbench": "~3.5.0",
"phpunit/phpunit": "~6.0",
"phpunit/phpcov": "~4.0"
},
"autoload": {
"psr-4": {
Expand All @@ -33,9 +34,6 @@
"Arcanedev\\LaravelMarkdown\\Tests\\": "tests/"
}
},
"scripts": {
"testbench": "composer require --dev \"orchestra/testbench=~3.0\""
},
"extra": {
"laravel": {
"providers": [
Expand Down
18 changes: 14 additions & 4 deletions config/markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@

return [

/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Set Safe mode
| -----------------------------------------------------------------
*/

'safe-mode' => false,

/* -----------------------------------------------------------------
| Escape Cross-site scripting
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
| Allowing or not to escape the JavaScript in anchor tags.
| e.g. markdown like "[Link](javascript:alert('hello'))".
*/

'xss' => true,

/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Automatically link URLs
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
| Allowing or not to automatic-linking of URLs in your markdown.
*/

'urls' => true,

/* -----------------------------------------------------------------
| Escape Markups
| -----------------------------------------------------------------
| Allowing or not to escape the HTML markups.
*/

'markups' => true,

];
9 changes: 4 additions & 5 deletions phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
syntaxCheck="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests</directory>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<php>
Expand Down
6 changes: 4 additions & 2 deletions src/MarkdownParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public function __construct(Parsedown $parser)
*/
public function parse($content)
{
$this->parser->setUrlsLinked(config('markdown.urls', true));
$this->parser->setMarkupEscaped(config('markdown.markups', true));
$this->parser
->setSafeMode(config('markdown.safe-mode', false))
->setUrlsLinked(config('markdown.urls', true))
->setMarkupEscaped(config('markdown.markups', true));

if (config('markdown.xss', true)) {
$content = preg_replace('/(\[.*\])\(javascript:.*\)/', '$1(#)', $content);
Expand Down
20 changes: 10 additions & 10 deletions tests/Facades/MarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
*/
class MarkdownTest extends TestCase
{
/* ------------------------------------------------------------------------------------------------
| Test Functions
| ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Tests
| -----------------------------------------------------------------
*/

/** @test */
public function it_can_parse_markdown_into_html()
{
$this->assertEquals(
static::assertEquals(
'<h1>Hello</h1>',
Markdown::parse('# Hello')
);
Expand All @@ -32,7 +33,7 @@ public function it_parse_a_block_of_markdown_into_html()
echo 'This text is **bold**!';
$html = Markdown::end();

$this->assertEquals(
static::assertEquals(
"<h1>Hello</h1>\n<p>This text is <strong>bold</strong>!</p>",
$html
);
Expand All @@ -50,23 +51,22 @@ public function it_can_parse_via_blade_directive()
];

foreach ($expectations as $name => $expected) {
$this->assertEquals($expected, $view->make($name)->render());
static::assertEquals($expected, $view->make($name)->render());
}
}


/** @test */
public function it_can_clean_javascript_from_links()
{
$this->assertEquals(
static::assertEquals(
'<p><a href="#">Link</a></p>',
Markdown::parse("[Link](javascript:alert('hello'))")
);

$this->app['config']->set('markdown.xss', false);

$this->assertEquals(
'<p><a href="javascript:alert(\'hello\')">Link</a></p>',
static::assertEquals(
'<p><a href="javascript:alert(&#039;hello&#039;)">Link</a></p>',
Markdown::parse("[Link](javascript:alert('hello'))")
);
}
Expand Down
23 changes: 13 additions & 10 deletions tests/LaravelMarkdownServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
*/
class LaravelMarkdownServiceProviderTest extends TestCase
{
/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/

/** @var \Arcanedev\LaravelMarkdown\LaravelMarkdownServiceProvider */
private $provider;

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/

public function setUp()
{
parent::setUp();
Expand All @@ -35,10 +37,11 @@ public function tearDown()
parent::tearDown();
}

/* ------------------------------------------------------------------------------------------------
| Test Functions
| ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Tests
| -----------------------------------------------------------------
*/

/** @test */
public function it_can_be_instantiated()
{
Expand All @@ -50,7 +53,7 @@ public function it_can_be_instantiated()
];

foreach ($expectations as $expected) {
$this->assertInstanceOf($expected, $this->provider);
static::assertInstanceOf($expected, $this->provider);
}
}

Expand All @@ -61,6 +64,6 @@ public function it_can_provides()
\Arcanedev\LaravelMarkdown\Contracts\Parser::class,
];

$this->assertEquals($expected, $this->provider->provides());
static::assertEquals($expected, $this->provider->provides());
}
}
29 changes: 18 additions & 11 deletions tests/MarkdownParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function tearDown()
/** @test */
public function it_can_be_instantiated()
{
$this->assertInstanceOf(
static::assertInstanceOf(
\Arcanedev\LaravelMarkdown\MarkdownParser::class,
$this->parser
);
Expand All @@ -52,7 +52,7 @@ public function it_can_be_instantiated()
/** @test */
public function it_can_parse_markdown_into_html()
{
$this->assertEquals(
static::assertEquals(
'<h1>Hello</h1>',
$this->parser->parse('# Hello')
);
Expand All @@ -66,7 +66,7 @@ public function it_parse_a_block_of_markdown_into_html()
echo 'This text is **bold**!';
$html = $this->parser->end();

$this->assertEquals(
static::assertEquals(
"<h1>Hello</h1>\n<p>This text is <strong>bold</strong>!</p>",
$html
);
Expand All @@ -84,38 +84,45 @@ public function it_can_parse_via_blade_directive()
];

foreach ($expectations as $name => $expected) {
$this->assertEquals($expected, $view->make($name)->render());
static::assertEquals($expected, $view->make($name)->render());
}
}


/** @test */
public function it_can_clean_xss()
{
$this->assertEquals(
static::assertEquals(
'<p><a href="#">Link</a></p>',
$this->parser->parse("[Link](javascript:alert('hello'))")
);

$this->app['config']->set('markdown.xss', false);

$this->assertEquals(
'<p><a href="javascript:alert(\'hello\')">Link</a></p>',
static::assertEquals(
'<p><a href="javascript:alert(&#039;hello&#039;)">Link</a></p>',
$this->parser->parse("[Link](javascript:alert('hello'))")
);

$this->app['config']->set('markdown.safe-mode', true);

static::assertEquals(
'<p><a href="javascript%3Aalert(&#039;hello&#039;)">Link</a></p>',
$this->parser->parse("[Link](javascript:alert('hello'))")
);
}

/** @test */
public function it_can_escape_markups()
{
$this->assertEquals(
static::assertEquals(
'<p>&lt;b&gt;This is a script&lt;/b&gt;&lt;script&gt;alert(\'hello\');&lt;/script&gt;</p>',
$this->parser->parse("<b>This is a script</b><script>alert('hello');</script>")
);

$this->app['config']->set('markdown.markups', false);

$this->assertEquals(
static::assertEquals(
'<p><b>This is a script</b><script>alert(\'hello\');</script></p>',
$this->parser->parse("<b>This is a script</b><script>alert('hello');</script>")
);
Expand All @@ -126,14 +133,14 @@ public function it_can_autolink_the_urls()
{
$md = 'You can find Parsedown at http://parsedown.org';

$this->assertEquals(
static::assertEquals(
'<p>You can find Parsedown at <a href="http://parsedown.org">http://parsedown.org</a></p>',
$this->parser->parse($md)
);

$this->app['config']->set('markdown.urls', false);

$this->assertEquals(
static::assertEquals(
'<p>You can find Parsedown at http://parsedown.org</p>',
$this->parser->parse($md)
);
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ protected function getPackageAliases($app)
*/
protected function getEnvironmentSetUp($app)
{
/** @var \Illuminate\Config\Repository $config */
/** @var \Illuminate\Config\Repository $config */
$config = $app['config'];

$config->set('view.paths', [realpath(__DIR__ . '/fixtures/views')]);
$config->set('view.paths', [
realpath(__DIR__ . '/fixtures/views')
]);
}
}

0 comments on commit 7f258af

Please sign in to comment.