1
0
mirror of https://github.com/erusev/parsedown.git synced 2025-09-04 20:25:27 +02:00

Compare commits

...

11 Commits
1.7.2 ... 1.7.x

Author SHA1 Message Date
Emanuil Rusev
d26023e306 Merge pull request #873 from xabbuh/ci
run tests using GitHub actions
2024-07-12 17:59:16 +03:00
Christian Flothmann
61a6072fd8 run tests using GitHub actions 2024-07-09 20:22:08 +02:00
Emanuil Rusev
f7285e7b2c Merge pull request #871 from xabbuh/pr-868-1.7
[PHP 8.4] Fixes for implicit nullability deprecation
2024-07-09 12:26:36 +03:00
Ayesh Karunaratne
7b307a9237 [PHP 8.4] Fixes for implicit nullability deprecation
Fixes all issues that emit deprecation notices on PHP 8.4 for implicit nullable parameter type declarations.

See:
 - [RFC](https://wiki.php.net/rfc/deprecate-implicitly-nullable-types)
 - [PHP 8.4: Implicitly nullable parameter declarations deprecated](https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated)
2024-07-09 10:54:21 +02:00
Aidan Woods
cb17b6477d Increment version for release 2019-12-30 22:54:17 +00:00
Aidan Woods
21f99b156a Merge pull request #745 from aidantwoods/dev-1.7.x/opt-in-rawHtml
Opt in raw html
2019-12-30 22:51:57 +00:00
Aidan Woods
791faca8af Test on 7.4 2019-12-30 22:47:43 +00:00
Aidan Woods
add8d18c80 Add rawHtml without using it (extensions may opt-in) 2019-12-30 22:37:17 +00:00
Aidan Woods
7073ac3ed1 Dev for 1.7.4 2019-12-30 22:37:17 +00:00
Aidan Woods
3d2b25b79d Add test to prevent regression 2019-04-10 21:49:32 +01:00
Aidan Woods
6d89393817 New release due to mislabeled previous tag 2019-03-17 18:48:37 +00:00
9 changed files with 153 additions and 7 deletions

42
.github/workflows/unit-tests.yaml vendored Normal file
View File

@@ -0,0 +1,42 @@
on:
- push
- pull_request
jobs:
phpunit:
runs-on: ubuntu-latest
strategy:
matrix:
php:
- '5.3'
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
- '8.4'
steps:
- name: Checkout the source code
uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
- name: Install dependencies
run: composer install
- name: Run tests
run: |
vendor/bin/phpunit
vendor/bin/phpunit test/CommonMarkTestWeak.php || true

View File

@@ -14,6 +14,7 @@ matrix:
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
- php: nightly
fast_finish: true
allow_failures:

View File

@@ -17,7 +17,7 @@ class Parsedown
{
# ~
const version = '1.7.2';
const version = '1.7.4';
# ~
@@ -1489,22 +1489,41 @@ class Parsedown
}
}
$permitRawHtml = false;
if (isset($Element['text']))
{
$text = $Element['text'];
}
// very strongly consider an alternative if you're writing an
// extension
elseif (isset($Element['rawHtml']))
{
$text = $Element['rawHtml'];
$allowRawHtmlInSafeMode = isset($Element['allowRawHtmlInSafeMode']) && $Element['allowRawHtmlInSafeMode'];
$permitRawHtml = !$this->safeMode || $allowRawHtmlInSafeMode;
}
if (isset($text))
{
$markup .= '>';
if (!isset($Element['nonNestables']))
if (!isset($Element['nonNestables']))
{
$Element['nonNestables'] = array();
}
if (isset($Element['handler']))
{
$markup .= $this->{$Element['handler']}($Element['text'], $Element['nonNestables']);
$markup .= $this->{$Element['handler']}($text, $Element['nonNestables']);
}
elseif (!$permitRawHtml)
{
$markup .= self::escape($text, true);
}
else
{
$markup .= self::escape($Element['text'], true);
$markup .= $text;
}
$markup .= '</'.$Element['name'].'>';

View File

@@ -17,7 +17,7 @@
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35"
"phpunit/phpunit": "^4.8|^5.7|^6.5|^7.5|^8.5|^9.6"
},
"autoload": {
"psr-0": {"Parsedown": ""}

View File

@@ -1,11 +1,13 @@
<?php
use PHPUnit\Framework\TestCase;
/**
* Test Parsedown against the CommonMark spec
*
* @link http://commonmark.org/ CommonMark
*/
class CommonMarkTestStrict extends PHPUnit_Framework_TestCase
class CommonMarkTestStrict extends TestCase
{
const SPEC_URL = 'https://raw.githubusercontent.com/jgm/CommonMark/master/spec.txt';

View File

@@ -1,5 +1,7 @@
<?php
require 'SampleExtensions.php';
use PHPUnit\Framework\TestCase;
class ParsedownTest extends TestCase
@@ -55,6 +57,40 @@ class ParsedownTest extends TestCase
$this->assertEquals($expectedMarkup, $actualMarkup);
}
function testRawHtml()
{
$markdown = "```php\nfoobar\n```";
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
$expectedSafeMarkup = '<pre><code class="language-php">&lt;p&gt;foobar&lt;/p&gt;</code></pre>';
$unsafeExtension = new UnsafeExtension;
$actualMarkup = $unsafeExtension->text($markdown);
$this->assertEquals($expectedMarkup, $actualMarkup);
$unsafeExtension->setSafeMode(true);
$actualSafeMarkup = $unsafeExtension->text($markdown);
$this->assertEquals($expectedSafeMarkup, $actualSafeMarkup);
}
function testTrustDelegatedRawHtml()
{
$markdown = "```php\nfoobar\n```";
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
$expectedSafeMarkup = $expectedMarkup;
$unsafeExtension = new TrustDelegatedExtension;
$actualMarkup = $unsafeExtension->text($markdown);
$this->assertEquals($expectedMarkup, $actualMarkup);
$unsafeExtension->setSafeMode(true);
$actualSafeMarkup = $unsafeExtension->text($markdown);
$this->assertEquals($expectedSafeMarkup, $actualSafeMarkup);
}
function data()
{
$data = array();

39
test/SampleExtensions.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
class UnsafeExtension extends Parsedown
{
protected function blockFencedCodeComplete($Block)
{
$text = $Block['element']['text']['text'];
unset($Block['element']['text']['text']);
// WARNING: There is almost always a better way of doing things!
//
// This example is one of them, unsafe behaviour is NOT needed here.
// Only use this if you trust the input and have no idea what
// the output HTML will look like (e.g. using an external parser).
$Block['element']['text']['rawHtml'] = "<p>$text</p>";
return $Block;
}
}
class TrustDelegatedExtension extends Parsedown
{
protected function blockFencedCodeComplete($Block)
{
$text = $Block['element']['text']['text'];
unset($Block['element']['text']['text']);
// WARNING: There is almost always a better way of doing things!
//
// This behaviour is NOT needed in the demonstrated case.
// Only use this if you are sure that the result being added into
// rawHtml is safe.
// (e.g. using an external parser with escaping capabilities).
$Block['element']['text']['rawHtml'] = "<p>$text</p>";
$Block['element']['text']['allowRawHtmlInSafeMode'] = true;
return $Block;
}
}

View File

@@ -8,4 +8,6 @@ echo $message;</code></pre>
<pre><code class="language-html+php">&lt;?php
echo "Hello World";
?&gt;
&lt;a href="http://auraphp.com" &gt;Aura Project&lt;/a&gt;</code></pre>
&lt;a href="http://auraphp.com" &gt;Aura Project&lt;/a&gt;</code></pre>
<pre><code class="language-php">&lt;?php
echo "Hello World";</code></pre>

View File

@@ -22,4 +22,9 @@ echo 'language identifier with non words';
echo "Hello World";
?>
<a href="http://auraphp.com" >Aura Project</a>
```
```php some-class
<?php
echo "Hello World";
```