From 9afd12807a27cf13766647ed4af938cca501beab Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Sun, 21 Apr 2019 13:12:55 +0100 Subject: [PATCH] Updating the package --- .scrutinizer.yml | 2 +- .travis.yml | 9 ++---- LICENSE.md | 2 +- composer.json | 10 +++---- config/markdown.php | 18 +++++++++--- phpunit.xml => phpunit.xml.dist | 9 +++--- src/MarkdownParser.php | 6 ++-- tests/Facades/MarkdownTest.php | 20 +++++++------- tests/LaravelMarkdownServiceProviderTest.php | 23 +++++++++------- tests/MarkdownParserTest.php | 29 ++++++++++++-------- tests/TestCase.php | 6 ++-- 11 files changed, 76 insertions(+), 58 deletions(-) rename phpunit.xml => phpunit.xml.dist (81%) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index d44a72f..69d4755 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -22,7 +22,7 @@ checks: tools: external_code_coverage: timeout: 600 - runs: 2 + runs: 4 php_code_sniffer: enabled: true config: diff --git a/.travis.yml b/.travis.yml index 03a87c5..b188562 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/LICENSE.md b/LICENSE.md index 9170660..4c6c967 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016-2017 | ARCANEDEV - LaravelMarkdown +Copyright (c) 2016-2019 | ARCANEDEV - 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 diff --git a/composer.json b/composer.json index d4e7dba..f1bf5d0 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -33,9 +34,6 @@ "Arcanedev\\LaravelMarkdown\\Tests\\": "tests/" } }, - "scripts": { - "testbench": "composer require --dev \"orchestra/testbench=~3.0\"" - }, "extra": { "laravel": { "providers": [ diff --git a/config/markdown.php b/config/markdown.php index 4216e29..9d87665 100644 --- a/config/markdown.php +++ b/config/markdown.php @@ -2,19 +2,28 @@ 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, /* ----------------------------------------------------------------- @@ -22,6 +31,7 @@ | ----------------------------------------------------------------- | Allowing or not to escape the HTML markups. */ + 'markups' => true, ]; diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 81% rename from phpunit.xml rename to phpunit.xml.dist index f7b46b1..2d393c4 100644 --- a/phpunit.xml +++ b/phpunit.xml.dist @@ -8,16 +8,15 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" - > + syntaxCheck="false"> - - ./tests + + ./tests/ - ./src + ./src/ diff --git a/src/MarkdownParser.php b/src/MarkdownParser.php index b7dcb71..df58e87 100644 --- a/src/MarkdownParser.php +++ b/src/MarkdownParser.php @@ -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); diff --git a/tests/Facades/MarkdownTest.php b/tests/Facades/MarkdownTest.php index 5ee65b6..0b10f8f 100644 --- a/tests/Facades/MarkdownTest.php +++ b/tests/Facades/MarkdownTest.php @@ -11,14 +11,15 @@ */ class MarkdownTest extends TestCase { - /* ------------------------------------------------------------------------------------------------ - | Test Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Tests + | ----------------------------------------------------------------- */ + /** @test */ public function it_can_parse_markdown_into_html() { - $this->assertEquals( + static::assertEquals( '

Hello

', Markdown::parse('# Hello') ); @@ -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( "

Hello

\n

This text is bold!

", $html ); @@ -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( '

Link

', Markdown::parse("[Link](javascript:alert('hello'))") ); $this->app['config']->set('markdown.xss', false); - $this->assertEquals( - '

Link

', + static::assertEquals( + '

Link

', Markdown::parse("[Link](javascript:alert('hello'))") ); } diff --git a/tests/LaravelMarkdownServiceProviderTest.php b/tests/LaravelMarkdownServiceProviderTest.php index d75560a..54c6d2a 100644 --- a/tests/LaravelMarkdownServiceProviderTest.php +++ b/tests/LaravelMarkdownServiceProviderTest.php @@ -10,17 +10,19 @@ */ class LaravelMarkdownServiceProviderTest extends TestCase { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** @var \Arcanedev\LaravelMarkdown\LaravelMarkdownServiceProvider */ private $provider; - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + public function setUp() { parent::setUp(); @@ -35,10 +37,11 @@ public function tearDown() parent::tearDown(); } - /* ------------------------------------------------------------------------------------------------ - | Test Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Tests + | ----------------------------------------------------------------- */ + /** @test */ public function it_can_be_instantiated() { @@ -50,7 +53,7 @@ public function it_can_be_instantiated() ]; foreach ($expectations as $expected) { - $this->assertInstanceOf($expected, $this->provider); + static::assertInstanceOf($expected, $this->provider); } } @@ -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()); } } diff --git a/tests/MarkdownParserTest.php b/tests/MarkdownParserTest.php index 54b8dd4..32788c3 100644 --- a/tests/MarkdownParserTest.php +++ b/tests/MarkdownParserTest.php @@ -43,7 +43,7 @@ public function tearDown() /** @test */ public function it_can_be_instantiated() { - $this->assertInstanceOf( + static::assertInstanceOf( \Arcanedev\LaravelMarkdown\MarkdownParser::class, $this->parser ); @@ -52,7 +52,7 @@ public function it_can_be_instantiated() /** @test */ public function it_can_parse_markdown_into_html() { - $this->assertEquals( + static::assertEquals( '

Hello

', $this->parser->parse('# Hello') ); @@ -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( "

Hello

\n

This text is bold!

", $html ); @@ -84,7 +84,7 @@ 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()); } } @@ -92,15 +92,22 @@ public function it_can_parse_via_blade_directive() /** @test */ public function it_can_clean_xss() { - $this->assertEquals( + static::assertEquals( '

Link

', $this->parser->parse("[Link](javascript:alert('hello'))") ); $this->app['config']->set('markdown.xss', false); - $this->assertEquals( - '

Link

', + static::assertEquals( + '

Link

', + $this->parser->parse("[Link](javascript:alert('hello'))") + ); + + $this->app['config']->set('markdown.safe-mode', true); + + static::assertEquals( + '

Link

', $this->parser->parse("[Link](javascript:alert('hello'))") ); } @@ -108,14 +115,14 @@ public function it_can_clean_xss() /** @test */ public function it_can_escape_markups() { - $this->assertEquals( + static::assertEquals( '

<b>This is a script</b><script>alert(\'hello\');</script>

', $this->parser->parse("This is a script") ); $this->app['config']->set('markdown.markups', false); - $this->assertEquals( + static::assertEquals( '

This is a script

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

You can find Parsedown at http://parsedown.org

', $this->parser->parse($md) ); $this->app['config']->set('markdown.urls', false); - $this->assertEquals( + static::assertEquals( '

You can find Parsedown at http://parsedown.org

', $this->parser->parse($md) ); diff --git a/tests/TestCase.php b/tests/TestCase.php index 82f9d6b..61dcfca 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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') + ]); } }