Skip to content

Commit 142b90c

Browse files
committed
RegularParser now properly takes into account escaped tokens, updated GitHub actions up to PHP 8.6
1 parent 8d66350 commit 142b90c

10 files changed

Lines changed: 44 additions & 6 deletions

File tree

.github/workflows/test.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ jobs:
1111
runs-on: '${{ matrix.os }}'
1212
strategy:
1313
matrix:
14-
php: ['7.4', '8.0', '8.1', '8.2', '8.3']
14+
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
1515
os: ['ubuntu-latest']
1616
failure: [false]
1717
include:
18-
- { php: '8.4', os: 'ubuntu-latest', failure: true } # Psalm does not support PHP 8.4 yet
19-
- { php: '8.5', os: 'ubuntu-latest', failure: true } # '8.5' means 'nightly'
18+
- { php: '8.6', os: 'ubuntu-latest', failure: true } # '8.6' means 'nightly'
2019
steps:
2120
- name: 'Checkout'
2221
uses: 'actions/checkout@v4'
@@ -38,7 +37,7 @@ jobs:
3837
- name: 'Psalm'
3938
run: |
4039
composer remove --dev -W 'phpunit/phpunit'
41-
composer require --dev -W 'vimeo/psalm=^5.0' 'nikic/php-parser=^4.0'
40+
composer require --dev -W 'vimeo/psalm=>=5.0' 'nikic/php-parser=>=4.0'
4241
php vendor/bin/psalm --shepherd --php-version=${{ matrix.php }}
4342
continue-on-error: '${{ matrix.failure }}'
4443
- name: 'Infection'

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PHP_VERSION ?= 8.0
1+
PHP_VERSION ?= 8.5
22
PHP := docker-compose run --rm php-${PHP_VERSION}
33

44
php-version:

docker-compose.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ services:
1818
php-7.3: { <<: *php, build: { context: docker/php, args: { PHP_VERSION: 7.3 } } }
1919
php-7.4: { <<: *php, build: { context: docker/php, args: { PHP_VERSION: 7.4 } } }
2020
php-8.0: { <<: *php, build: { context: docker/php, args: { PHP_VERSION: 8.0 } } }
21+
php-8.1: { <<: *php, build: { context: docker/php, args: { PHP_VERSION: 8.1 } } }
22+
php-8.2: { <<: *php, build: { context: docker/php, args: { PHP_VERSION: 8.2 } } }
23+
php-8.3: { <<: *php, build: { context: docker/php, args: { PHP_VERSION: 8.3 } } }
24+
php-8.4: { <<: *php, build: { context: docker/php, args: { PHP_VERSION: 8.4 } } }
25+
php-8.5: { <<: *php, build: { context: docker/php, args: { PHP_VERSION: 8.5 } } }

docker/php/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ARG PHP_VERSION=8.0
22
FROM php:$PHP_VERSION
33

44
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
5-
&& php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
5+
&& php -r "if (hash_file('sha384', 'composer-setup.php') === 'c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
66
&& php composer-setup.php \
77
&& php -r "unlink('composer-setup.php');" \
88
&& mv composer.phar /usr/local/bin/composer

src/Parser/RegularParser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ private function prepareLexer(SyntaxInterface $syntax)
388388
$quote($syntax->getClosingTagMarker()),
389389
$quote($syntax->getParameterValueSeparator()),
390390
$quote($syntax->getParameterValueDelimiter()),
391+
'\\\\',
391392
'\s+',
392393
)).').)+)',
393394
'(?<ws>\s+)',

tests/ParserTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Thunder\Shortcode\Tests;
33

4+
use PHPUnit\Framework\Attributes\DataProvider;
45
use Thunder\Shortcode\HandlerContainer\HandlerContainer;
56
use Thunder\Shortcode\Parser\RegularParser;
67
use Thunder\Shortcode\Parser\ParserInterface;
@@ -23,6 +24,7 @@ final class ParserTest extends AbstractTestCase
2324
*
2425
* @dataProvider provideShortcodes
2526
*/
27+
#[DataProvider('provideShortcodes')]
2628
public function testParser(ParserInterface $parser, $code, array $expected)
2729
{
2830
$this->assertShortcodes($parser->parse($code), $expected);
@@ -276,6 +278,26 @@ public function testIssue77()
276278
));
277279
}
278280

281+
public function testIssue119()
282+
{
283+
$cases = [
284+
'[a k="\"y"]inner[/a]' => new ParsedShortcode(new Shortcode('a', array('k' => '\"y'), 'inner', null), '[a k="\"y"]inner[/a]', 0),
285+
'[a k=" \"y"]inner[/a]' => new ParsedShortcode(new Shortcode('a', array('k' => ' \"y'), 'inner', null), '[a k=" \"y"]inner[/a]', 0),
286+
'[a k=" x\"y"]inner[/a]' => new ParsedShortcode(new Shortcode('a', array('k' => ' x\"y'), 'inner', null), '[a k=" x\"y"]inner[/a]', 0),
287+
'[a k="x\"y"]inner[/a]' => new ParsedShortcode(new Shortcode('a', array('k' => 'x\"y'), 'inner', null), '[a k="x\"y"]inner[/a]', 0),
288+
'[mention id=1 name="foo\"ff\""][/mention]' => new ParsedShortcode(new Shortcode('mention', array('id' => '1', 'name' => 'foo\"ff\"'), '', null), '[mention id=1 name="foo\"ff\""][/mention]', 0),
289+
];
290+
$parser = new RegularParser();
291+
foreach($cases as $input => $expected) {
292+
$this->assertShortcodes($parser->parse($input), [$expected]);
293+
}
294+
295+
$this->assertShortcodes($parser->parse('[a k="x\"y"]inner[/a] [mention id=1 name="foo\"ff\""][/mention]'), [
296+
new ParsedShortcode(new Shortcode('a', array('k' => 'x\"y'), 'inner', null), '[a k="x\"y"]inner[/a]', 0),
297+
new ParsedShortcode(new Shortcode('mention', array('id' => '1', 'name' => 'foo\"ff\"'), '', null), '[mention id=1 name="foo\"ff\""][/mention]', 22),
298+
]);
299+
}
300+
279301
public function testWordPress()
280302
{
281303
$parser = new WordpressParser();

tests/ProcessorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Thunder\Shortcode\Tests;
33

4+
use PHPUnit\Framework\Attributes\DataProvider;
45
use Thunder\Shortcode\Handler\ContentHandler;
56
use Thunder\Shortcode\Handler\DeclareHandler;
67
use Thunder\Shortcode\Handler\EmailHandler;
@@ -62,6 +63,7 @@ public function testReplaceWithoutContentOffset()
6263
*
6364
* @dataProvider provideTexts
6465
*/
66+
#[DataProvider('provideTexts')]
6567
public function testProcessorProcess($text, $result)
6668
{
6769
$processor = new Processor(new RegexParser(), $this->getHandlers());
@@ -164,6 +166,7 @@ public function testProcessorShortcodePositions()
164166
/**
165167
* @dataProvider provideBuiltInTests
166168
*/
169+
#[DataProvider('provideBuiltInTests')]
167170
public function testBuiltInHandlers($text, $result)
168171
{
169172
$handlers = new HandlerContainer();

tests/SerializerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Thunder\Shortcode\Tests;
33

4+
use PHPUnit\Framework\Attributes\DataProvider;
45
use Thunder\Shortcode\Serializer\JsonSerializer;
56
use Thunder\Shortcode\Serializer\SerializerInterface;
67
use Thunder\Shortcode\Serializer\TextSerializer;
@@ -18,6 +19,7 @@ final class SerializerTest extends AbstractTestCase
1819
/**
1920
* @dataProvider provideShortcodes
2021
*/
22+
#[DataProvider('provideShortcodes')]
2123
public function testSerializer(SerializerInterface $serializer, ShortcodeInterface $test)
2224
{
2325
$result = $serializer->serialize($test);
@@ -61,6 +63,7 @@ public static function provideShortcodes()
6163
/**
6264
* @dataProvider provideUnserialized
6365
*/
66+
#[DataProvider('provideUnserialized')]
6467
public function testUnserialize(SerializerInterface $serializer, ShortcodeInterface $test, $text)
6568
{
6669
$tested = $serializer->unserialize($text);
@@ -89,6 +92,7 @@ public static function provideUnserialized()
8992
/**
9093
* @dataProvider provideExceptions
9194
*/
95+
#[DataProvider('provideExceptions')]
9296
public function testSerializerExceptions(SerializerInterface $serializer, $value, $exceptionClass)
9397
{
9498
$this->willThrowException($exceptionClass);

tests/ShortcodeTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Thunder\Shortcode\Tests;
33

4+
use PHPUnit\Framework\Attributes\DataProvider;
45
use Thunder\Shortcode\HandlerContainer\HandlerContainer;
56
use Thunder\Shortcode\Parser\RegexParser;
67
use Thunder\Shortcode\Processor\Processor;
@@ -18,6 +19,7 @@ final class ShortcodeTest extends AbstractTestCase
1819
/**
1920
* @dataProvider provideShortcodes
2021
*/
22+
#[DataProvider('provideShortcodes')]
2123
public function testShortcode($expected, $name, array $args, $content)
2224
{
2325
$s = new Shortcode($name, $args, $content);

tests/SyntaxTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Thunder\Shortcode\Tests;
33

4+
use PHPUnit\Framework\Attributes\DataProvider;
45
use Thunder\Shortcode\Syntax\Syntax;
56
use Thunder\Shortcode\Syntax\CommonSyntax;
67
use Thunder\Shortcode\Syntax\SyntaxBuilder;
@@ -14,6 +15,7 @@ final class SyntaxTest extends AbstractTestCase
1415
/**
1516
* @dataProvider provideSyntaxes
1617
*/
18+
#[DataProvider('provideSyntaxes')]
1719
public function testSyntax(SyntaxInterface $syntax, $open, $close, $slash, $parameter, $value)
1820
{
1921
static::assertSame($open, $syntax->getOpeningTag());

0 commit comments

Comments
 (0)