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

Fix scanner for Windows line endings and add tests #71

Merged
merged 1 commit into from
Dec 1, 2015

Conversation

jen20
Copy link
Contributor

@jen20 jen20 commented Dec 1, 2015

I think this should be enough to fix hashicorp/terraform#4069, though this is not yet verified and changes to the parser may also be necessary.

@jen20 jen20 added the bug label Dec 1, 2015
@@ -224,7 +224,11 @@ func (s *Scanner) scanComment(ch rune) {
// single line comments
if ch == '#' || (ch == '/' && s.peek() != '*') {
ch = s.next()
for ch != '\n' && ch >= 0 && ch != eof {
for ch != '\n' && ch != '\r' && ch >= 0 && ch != eof {
if ch == '\r' && s.peek() == '\n' {
Copy link
Contributor

Choose a reason for hiding this comment

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

Confused about how if the guard has && ch != '\r' this conditional will ever be true.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh sorry - by "the guard" I mean the one on L227.

Copy link
Contributor

Choose a reason for hiding this comment

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

In other words, I believe this will break comments immediately on \r instead of only on \r\n... which might be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a typo (originally the whole guard was one line). Will fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The question is do we want the \r to be included in the comment or treated as part of the line break? Unlike HEREDOCs I'd say they should be part of the line break for comments (though unless we're going to process comments it doesn't make much difference).

@mitchellh
Copy link
Contributor

On first pass something about this looks a little weird.

The ch != 'r' test doesn't seem necessary in the for loop.

I didn't check the rest of the code but I believe due to how the scanner works the newline character(s) still show up in the Token text correct? I'm not sure if this is okay or not but it is worth questioning to make sure it is correct.

@jen20
Copy link
Contributor Author

jen20 commented Dec 1, 2015

@mitchellh The loop was a typo - now fixed. The current situation with this PR is:

  • comments have the \r as part of the token text
  • HEREDOCs keep the \r throughout (which is probably OK - unless we want to handle line ending conversion in e.g. Windows provisioners), but the \r can be part of the anchor so they terminate correctly.

@phinze
Copy link
Contributor

phinze commented Dec 1, 2015

@jen20 and I both reviewed pre-rewrite behavior and confirmed that the behavior as he just described it was the same. this LGTM

phinze added a commit that referenced this pull request Dec 1, 2015
Fix scanner for Windows line endings and add tests
@phinze phinze merged commit c40ec20 into master Dec 1, 2015
@phinze phinze deleted the b-dos-line-endings branch December 1, 2015 18:18
apparentlymart pushed a commit that referenced this pull request Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syntax error with heredoc's on Windows in TF v0.6.7
3 participants