Skip to content

Array format with trailing comma weird behavior #58

@ktzouno

Description

@ktzouno

Hello,

I noticed a weird behavior when the matching pattern contains an array with a trailing comma after the final element as seen in the example and it's output below.

I'd expect the trailing comma to be ignored in the "First" test below and not throw an error.
But take a look at the "Second" test, where the error is incorrectly about the @null@ formatter.

<?php
use Coduo\PHPMatcher\Factory\SimpleFactory;

$factory = new SimpleFactory();
$matcher = $factory->createMatcher();

$match = $matcher->match(
    '{"ids": [1, 2]}',
    '{"ids": [@integer@, @integer@,]}'
);

if (!$match) {
    echo "First: " . $matcher->getError() . "\n";
}

$match = $matcher->match(
    '{"value": null, "ids": [1, 2]}',
    '{"value": @null@, "ids": [@integer@, @integer@,]}'
);

if (!$match) {
    echo "Second: " . $matcher->getError() . "\n";
}

Output:
First: "{"ids": [1, 2]}" does not match "{"ids": [@integer@, @integer@,]}" pattern
Second: Type pattern "@null@" is not supported by TextMatcher.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions