FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: disallow string callables by ramsey · Pull Request #53 · Skillshare/formatphp · GitHub

fix: disallow string callables - #53

Merged
ramsey merged 2 commits into
mainfrom
string-callable-bug
May 23, 2022
Merged

fix: disallow string callables#53
ramsey merged 2 commits into
mainfrom
string-callable-bug

Conversation

ramsey commented May 23, 2022

Copy link
Copy Markdown
Contributor

Description

We've encountered some cases where the string values "max," "floor," and "tan" were passed as values to replace placeholders in formatted messages. However, since we were doing an is_callable() check on the strings, and PHP has functions with these names, FormatPHP was attempting to call the functions instead of treating them as strings that should replace the placeholders.

Since we should never call a function that is potentially provided from user input, we will disallow the use of string callables. Only array callables and Closures are allowed.

Product requirements and context

How has this been tested?

PR Checklist

  • I have added tests to cover my changes.

ramsey marked this pull request as ready for review May 23, 2022 18:39
ramsey requested review from chrisl-13, jrode and tcarrio May 23, 2022 18:41

Copy link
Copy Markdown

Code Climate has analyzed commit a282d76 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (80% is the threshold).

This pull request will bring the total coverage in the repository to 97.6% (0.0% change).

View more on Code Climate.

ramsey merged commit 4ded2e2 into main May 23, 2022
ramsey deleted the string-callable-bug branch May 23, 2022 19:16
public function testStringsMustNotEvaluateAsCallables(): void
{
$message = 'Hello, {firstName} {lastName}!';
$expected = 'Hello, Ceil Floor!';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

👋 😄

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL