Skip to content

Conversation

schlessera
Copy link
Member

Using a regular expression to match all __FILE__ and __DIR__ constants that are not wrapped in quotes ( see https://regex101.com/r/9hXp5d/2/ ), we replace these with single-quoted strings that are the realpath() of the current file, or the dirname() of that file, respectively.

Fixes #37

@schlessera schlessera requested a review from a team as a code owner April 10, 2019 08:27
@danielbachhuber danielbachhuber added this to the 2.0.3 milestone Apr 10, 2019
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

Nice find!

@danielbachhuber danielbachhuber merged commit fc44091 into master Apr 10, 2019
@delete-merged-branch delete-merged-branch bot deleted the 37-fix-file-constant branch April 10, 2019 12:14
@t-my
Copy link

t-my commented May 9, 2019

This caused regression while running from crontab file, require 'file.php' didn't work anymore as previously, requiring the file in the same folder than the called script.

I had crontab * * * * * wp eval-file /directory/script.php

script.php: require 'file.php'

and the /directory contained file.php

Got error from the script.php file: unable to find file.php

schlessera pushed a commit that referenced this pull request Jan 5, 2022
Fix handling of `__FILE__` and `__DIR__` constants in `eval()`'d code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eval she-bang handling breaks __FILE__ constant
3 participants