mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Handle invalid indentation
This commit is contained in:
parent
e167703ba3
commit
1bf9ad8737
3 changed files with 23 additions and 3 deletions
|
@ -1,12 +1,12 @@
|
|||
require 'hamlit/concerns/error'
|
||||
|
||||
module Hamlit
|
||||
EOF = -1
|
||||
|
||||
module Concerns
|
||||
module Indentable
|
||||
include Concerns::Error
|
||||
|
||||
EOF = -1
|
||||
|
||||
def reset_indent
|
||||
@current_indent = 0
|
||||
end
|
||||
|
|
|
@ -47,7 +47,19 @@ module Hamlit
|
|||
# Parse lines in current_indent and return ASTs.
|
||||
def parse_lines
|
||||
ast = []
|
||||
while next_indent == @current_indent
|
||||
loop do
|
||||
indent = next_indent
|
||||
if indent != @current_indent
|
||||
if indent != Hamlit::EOF && indent > @current_indent
|
||||
ast << [:newline]
|
||||
ast << syntax_error(
|
||||
"inconsistent indentation: #{2 * @current_indent} spaces used for indentation, "\
|
||||
"but the rest of the document was indented using #{next_line[/\A +/].to_s.length} spaces"
|
||||
)
|
||||
end
|
||||
break
|
||||
end
|
||||
|
||||
@current_lineno += 1
|
||||
node = parse_line(current_line)
|
||||
if @outer_removal.include?(@current_indent) && ast.last == [:static, "\n"]
|
||||
|
|
|
@ -6,5 +6,13 @@ describe Hamlit::Engine do
|
|||
"There's no Ruby code for = to evaluate.",
|
||||
)
|
||||
end
|
||||
|
||||
it 'raises syntax error for illegal indentation' do
|
||||
expect { render_string(<<-HAML.unindent) }.
|
||||
%a
|
||||
%b
|
||||
HAML
|
||||
to raise_error(Hamlit::SyntaxError, 'inconsistent indentation: 2 spaces used for indentation, but the rest of the document was indented using 4 spaces')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue