-
Notifications
You must be signed in to change notification settings - Fork 44
Fix parsing here-docs without a carriage return after the terminator #72
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
Fix parsing here-docs without a carriage return after the terminator #72
Conversation
These tests are a nice addition to the test suite. With them in place, the 'HEREDOC' block in t/ppi_token_operator.t can be removed. An unterminated heredoc appears to actually a perl runtime abort, not a warning, which make the comment alluded to wrong. If it were just a warning, one of these two examples would execute their 'die':
This makes me question whether PPI should create a HereDoc if the newline is missing from the heredoc terminator. |
Indeed. I just pushed a678d80 accordingly.
Ah yes, I checked quickly before writing the patch but I guess a trailing return must have sneaked in when I was editing the file. Your examples are definitely conclusive.
This would open a bunch of follow-up questions:
I'm happy to amend the pull request, just let me know. |
Any incomplete thing of any kind at the end of a file should, where Assume you just started typing into an empty document. What will the final That's what you parse to. Adam
|
Thank you, @adamkennedy. I've just updated (in cc7ba81) the original comment to indicate that Perl will fail compilation (per @moregan's note) but left the pull request in its current form to achieve what you described. Let me know if you would like me to make any further modifications. |
I'm happy to make any further modifications, just let me know. |
Before i'll be able to release this, i must get out a proper release, the steps towards which i've taken in #81. Once that is done, i will address this pull request. :) |
@wchristian - Thank you for the update, and good luck with the upcoming release! :) |
dcc718c
to
04bd318
Compare
Rebased on master and cleaned up. If everything goes well this is slated to be out in 1.222 in two to three weeks. |
Diagnostic
PPI::Token::HereDoc
notes that:In the
__TOKENIZER__on_char()
subroutine, the parsing of this use case is handled by this conditional block, which requires$line
to be defined:However, because of the condition in the while loop that precedes that block,
$line
will always be undefined after the while loop finishes:The current code then considers the terminator without trailing newline to be part of the content of an unterminated here-doc, which is incorrect per the original comment in the code.
Pull Request
This pull request provides the following:
$token->{_heredoc}->[-1]
instead of$line
to detect terminators at the end of the file.$token->{_heredoc}->[-1]
will always contain the last line of the file and this is what needs to be considered for parsing of the trailing terminator without carriage return afterwards.$line
to the while() loop only, since it is not used outside of it anymore.PPI::Tokenizer
at the end of the PPI document, when the here-doc block is at the end of the file. It was already correctly removed for unterminated here-docs, but it needs to be removed as well for here-docs with a proper terminator but without a carriage return at the end. This also allows the$token->{_heredoc}->[-1] eq $token->{_terminator}
comparison to work properly.Thank you!