Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape percent sign in Assert::notSame message #1690

Merged
merged 1 commit into from
May 11, 2022
Merged

Escape percent sign in Assert::notSame message #1690

merged 1 commit into from
May 11, 2022

Conversation

villfa
Copy link
Contributor

@villfa villfa commented May 11, 2022

This PR fixes #1662

The 3rd argument of Webmozart\Assert\Assert::notSame is passed to sprintf:

    public static function notSame($value, $expect, $message = '')
    {
        if ($expect === $value) {
            static::reportInvalidArgument(\sprintf(
                $message ?: 'Expected a value not identical to %s.',
                static::valueToString($expect)
            ));
        }
    }

See https://github.com/webmozarts/assert/blob/dc96b67/src/Assert.php#L831-L839

If we call it with a message containing %~ then PHP thows ValueError: Unknown format specifier "~".

This PR escapes the % sign to avoid this error.

Copy link
Member

@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @villfa

@maks-rafalko maks-rafalko merged commit 134853c into infection:master May 11, 2022
@maks-rafalko maks-rafalko added this to the next milestone May 11, 2022
@maks-rafalko
Copy link
Member

@villfa villfa deleted the fix/1662 branch May 11, 2022 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Infection do not working on PHP 8.1.1.
2 participants