-
Notifications
You must be signed in to change notification settings - Fork 8
Fixed - was not working for variables in last line of heredoc. #14
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
Fixed - was not working for variables in last line of heredoc. #14
Conversation
It seems that heredoc() method excludes terminator line, so no need to pop() https://metacpan.org/pod/PPI::Token::HereDoc#heredoc added test for the bug, also added additional test to extract_variables (just to make sure our regexp deals with newlines right)
Hi Victor, Thank you for your pull request, and in particular for including a test :) You found a really interesting bug in how PPI's tokenizer handles heredoc blocks. Due to this bug, quoted heredoc blocks (such as
But unquoted heredoc blocks (such as
I must have been testing with quoted heredocs when I wrote the code, hence the original line I had there. I submitted a pull request to @adamkennedy to fix the underlying inconsistency and match the documentation: Perl-Critic/PPI#71. In the meantime, I'm going to merge your pull request, and add a conditional on top to handle the inconsistency. Once the pull request is merged in PPI's repository, I will have to also add a test for PPI's version in that code, or require a minimum version of PPI. |
Due to a bug in PPI::Token::Heredoc, $token->heredoc() does not include the terminator line when the terminator is a simple bareword, but it includes the terminator line in the other cases (single/double quoted , commands, escaped). I wrote a patch to resolve this in PPI (see Perl-Critic/PPI#71), but in the meantime this addresses the inconsistency.
a bit strange. I've tried to add new test (and I commented out pop() for testing and removed all other tests):
and it seems heredoc contains "SELECT" in last element if the .run file ends with 0 or 1 newline. and does not contain "SELECT" if .run file ends with 2+ newlines or there are other statements after heredoc. and this was not related to quoting of select. |
This reverts commit 49b2c9b. Upon further investigation, I found that the issue is not in PPI but in the test cases in this module. I will commit a fix for those separately, but I am reverting the PPI workaround and I have cancelled the PPI pull request accordingly.
The closing terminator should not include quotes/backticks/etc, or it will not be detected as a valid closing terminator and be included in the heredoc() output instead, which is the real cause of the issues we've seen in GH-14.
I investigated further and found the issue - your patch was indeed correct, and I reverted my later modification. The issue turned out to be in the test cases, which I fixed with eef8806. |
Regarding your new SELECT test case above - I can reproduce it, but only if there is no newline after SELECT. Can you confirm it breaks with 1 newline as well for you? |
yes. I sent PR-17 as example. Also travis should confirm that it's failing. It seems PPI problem indeed, but I think it's very low priority for your module. Affected:
other cases probably can include heredocs terminators with sigils, which is just waiting for trouble anyway. |
Thank you for opening GH-17 to track this PPI issue! I'm going to follow up there. |
It seems that heredoc() method excludes terminator line, so no need to pop()
https://metacpan.org/pod/PPI::Token::HereDoc#heredoc
added test for the bug, also added additional test to extract_variables (just
to make sure our regexp deals with newlines right)