OWS / commonmark-sup-sub-extensions

A sup/sub extension for CommonMark PHP implementation
GNU General Public License v3.0
9 stars 6 forks source link

Incorrect escaping in sup marks #4

Closed rbairwell closed 5 years ago

rbairwell commented 5 years ago

Using commonmark-sup-sub-extensions 1.1.0 and commonmark 0.18.3 , the following test case:

<?php
declare(strict_types=1);

use League\CommonMark\Environment as CommonMarkEnvironment;
use Ows\CommonMark\SupExtension;

include __DIR__.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php';

$environment = CommonMarkEnvironment::createCommonMarkEnvironment();
$environment->addExtension(new SupExtension());
$markdown=new \League\CommonMark\CommonMarkConverter([],$environment);
echo $markdown->convertToHtml('First [\[1\]](https://example.com) link').PHP_EOL;
echo $markdown->convertToHtml('Second [^1^](https://example.com) link').PHP_EOL;
echo $markdown->convertToHtml('Third [^\[1\]^](https://example.com) link').PHP_EOL;

incorrectly escapes the [1] in the link when it is surrounded by the ^ markers.

Here's the output:

<p>First <a href="https://example.com">[1]</a> link</p>

<p>Second <a href="https://example.com"><sup>1</sup></a> link</p>

<p>Third <a href="https://example.com"><sup>\[1\]</sup></a> link</p>

I expected:

<p>First <a href="https://example.com">[1]</a> link</p>

<p>Second <a href="https://example.com"><sup>1</sup></a> link</p>

<p>Third <a href="https://example.com"><sup>[1]</sup></a> link</p>

(i.e. square brackets on the third without escaping).

Tested against https://stackedit.io/app# with:

First [\[1\]](https://example.com) link
Second [^1^](https://example.com) link
Third [^\[1\]^](https://example.com) link
Sylry commented 5 years ago

Thanks for the test.

I can bypass the bug with 'Third [^[1]^](https://example.com) link' which outputs <p>Third <a href="https://example.com"><sup>[1]</sup></a> link</p>

But I agree that we should fix that

Sylry commented 5 years ago

This is now fixed in 2.x branch