Feature #8699

Feature request: Detect line encoding problems

Added by Matthew Sainsbury 9 months ago. Updated 8 months ago.

[ruby-core:56240]
Status:Closed
Priority:Normal
Assignee:Yui NARUSE
Category:-
Target version:-

Description

This is a feature which would have saved me hours of debugging.

If you give ruby a file with old mac line endings, ruby does not recognise them as new lines. I think this is ok because it's easy to convert to a format that ruby can deal with, but it would be great if ruby would recognise all these \r characters without any new lines and give a warning that there's probably an encoding problem.

For example, given this code:

hi "hello"[\r]
def hi(x)[\r]
puts x[\r]
end

instead of returning:

test.rb:1: syntax error, unexpected keyword_def, expecting end-of-input
end puts x
^

it would return

test.rb: Warning: Have you got the wrong line endings in this file? Both UNIX-style (\n) and Windows-style (\r\n) are recognised by ruby, but your file has something different.

Not really an urgent feature but it would be helpful in some cases. Shouldn't be too hard to implement

Associated revisions

Revision 42691
Added by Nobuyoshi Nakada 8 months ago

parse.y: warn CR

  • parse.y (parser_nextc): warn carriage return in middle of line. [Feature #8699]

History

#1 Updated by Koichi Sasada 8 months ago

  • Assignee set to Yui NARUSE

#2 Updated by Nobuyoshi Nakada 8 months ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r42691.
Matthew, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


parse.y: warn CR

  • parse.y (parser_nextc): warn carriage return in middle of line. [Feature #8699]

Also available in: Atom PDF