parsedown-extra-plugin icon indicating copy to clipboard operation
parsedown-extra-plugin copied to clipboard

Line 393: $Content is array when it should be string

Open hexakon opened this issue 2 years ago • 4 comments

<?php
    require 'Parsedown.php';
    require 'ParsedownExtra.php';
    require 'ParsedownExtraPlugin.php';
    
    $Parsedown = new ParsedownExtraPlugin;

    echo $Parsedown->text($text);
?>

The above code prints the expected output when the class Parsedown or ParsedownExtra is used. When using ParsedownExtraPlugin, I get the following error and stack trace in the output log (with parts of the filepath omitted)

Fatal error: Uncaught TypeError: explode(): Argument #2 ($string) must be of type string, array given in [C:\Users\...\docs\ParsedownExtraPlugin.php:393]()
Stack trace:
#0 [C:\Users\...\docs\ParsedownExtraPlugin.php]()(393): explode('\n', Array)
#1 [C:\Users\...\docs\ParsedownExtraPlugin.php]()(272): ParsedownExtraPlugin->doSetContent(Array, NULL, false, 'arguments')
#2 [C:\Users\...\docs\Parsedown.php]()(206): ParsedownExtraPlugin->blockQuoteComplete(Array)
#3 [C:\Users\...\docs\Parsedown.php]()(39): Parsedown->lines(Array)
#4 [C:\Users\...\docs\ParsedownExtra.php]()(46): Parsedown->text('In the beginnin...')
#5 [C:\Users\...\docs\read.php]()(57): ParsedownExtra->text('\n\r\nIn the begin...')
#6 {main}
  thrown in [C:\Users\...\docs\ParsedownExtraPlugin.php]() on line 393

hexakon avatar Feb 08 '22 17:02 hexakon

Can you provide the minimum text input, so that I can test it myself?

taufik-nurrohman avatar Feb 09 '22 00:02 taufik-nurrohman

here's the text I used:

In the beginning, the universe was created.

This line comes after a line break.

Can I inject html tags? <b>Lets see!</b>

> Here's a markdown quote and some *italics* and <u>underline</u> and ~~strike one~~
>
> additional quotes
>
> last row

1. one

2. two

* test

----

# test1

hi

![stoat](test/stoat.jpg)
 a humble stoate.

tested on php 8.1.2. It also doesn't work on 7.4.27, but I don't have the output log for it.

hexakon avatar Feb 09 '22 13:02 hexakon

Sorry, cannot reproduce the issue. Have you checked this pull request?

<?php

require 'vendor/autoload.php';

$Parsedown = new ParsedownExtraPlugin;

$text = <<<S
In the beginning, the universe was created.

This line comes after a line break.

Can I inject html tags? <b>Lets see!</b>

> Here's a markdown quote and some *italics* and <u>underline</u> and ~~strike one~~
>
> additional quotes
>
> last row

1. one

2. two

* test

----

# test1

hi

![stoat](test/stoat.jpg)
 a humble stoate.
S;

echo '<p><mark>' . PHP_VERSION . '</mark></p>';

echo $Parsedown->text($text);

?>

Screenshot 2022-02-09 at 22-56-49 Screenshot

taufik-nurrohman avatar Feb 09 '22 16:02 taufik-nurrohman

I've downdated ParsedownExtra to 0.8.0 and now receive this error log instead:

Fatal error: Uncaught Exception: Method textElements does not exists. in [C:\Users\...\docs\ParsedownExtraPlugin.php:86]()
Stack trace:
#0 [C:\Users\Coda\...\docs\ParsedownExtra.php]()(46): ParsedownExtraPlugin->__call('textElements', Array)
#1 [C:\Users\Coda\...\docs\read.php]()(62): ParsedownExtra->text('\nIn the beginni...')
#2 {main}
  thrown in [C:\Users\...\docs\ParsedownExtraPlugin.php]() on line 86

If it helps, I'm not using composer.

EDIT: I know this is unrelated to the plugin, but I just noticed that ParsedownExtra 0.8.0 doesn't work for me either (0.8.1 works fine). I get the following error log when I use the ParsedownExtra class (not ParsedownExtraPlugin), maybe it can be of some help:

Fatal error: Uncaught Error: Call to undefined method ParsedownExtra::textElements() in [C:\Users\...\docs\ParsedownExtra_0.8.0.php:46]()
Stack trace:
#0 [C:\Users\...\docs\read.php]()(62): ParsedownExtra->text('\nIn the beginni...')
#1 {main}
  thrown in [C:\Users\...\docs\ParsedownExtra_0.8.0.php]() on line 46

the undefined method in question, textElements(), was replaced in 0.8.1.

hexakon avatar Feb 09 '22 19:02 hexakon