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

Prevent generation of invalid code for certain parameter default values #901

Merged
merged 3 commits into from
Apr 21, 2020
Merged

Prevent generation of invalid code for certain parameter default values #901

merged 3 commits into from
Apr 21, 2020

Conversation

loilo
Copy link
Contributor

@loilo loilo commented Mar 25, 2020

Certain default values for method parameters (strings containing single quotes or trailing backslashes) currently generate an invalid _ide_helper.php file.

This PR fixes that by replacing the current naïve code generation with a call to var_export().

@mfn
Copy link
Collaborator

mfn commented Mar 26, 2020

Can you give an example how the code in practice looks like which triggers this?

I also think we should write tests for this

@loilo
Copy link
Contributor Author

loilo commented Mar 26, 2020

I agree. I have to admit that I was a little bit tired when I opened the PR and didn't have the patience to grasp the test structure of the repo. 😁

I encountered this problem when I made a facade for the loilo/x-filesystem package, the problem occurs with this method declaration (can be found here):

public function readCsvFile(
    string $filename,
    int $mode = self::PARSE_OBJECT,
    string $delimiter = ',',
    string $charset = 'UTF-8',
    string $enclosure = '"',   // <- If I change this to "'", it breaks as well
                               //    because it outputs '''
    string $escapeChar = '\\'  // <- This breaks because it outputs '\'
)

If you want me to, I can attach a minimal reproduction repo.

@loilo
Copy link
Contributor Author

loilo commented Mar 26, 2020

FWIW, I've added a test for these special characters in parameter default values.

@mfn
Copy link
Collaborator

mfn commented Mar 27, 2020

Tanks, will take a look ASAP!

Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

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

LGTM, also tested with a project "to be sure" 😄

tests/MethodTest.php Outdated Show resolved Hide resolved
@mfn
Copy link
Collaborator

mfn commented Mar 31, 2020

ping @barryvdh

@barryvdh barryvdh merged commit bef8158 into barryvdh:master Apr 21, 2020
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