Skip to content

Commit

Permalink
Merge pull request #48294 from tenderlove/fix-column-info
Browse files Browse the repository at this point in the history
Scan forward until text tokens match
  • Loading branch information
tenderlove committed May 24, 2023
2 parents ad9037a + 5e35463 commit 5513296
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions actionview/lib/action_view/template/handlers/erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,23 @@ def find_offset(compiled, source_tokens, error_column)
tok_name, str = *tok
case tok_name
when :TEXT
loop do
break if compiled.match?(str)
compiled.getch
end
raise LocationParsingError unless compiled.scan(str)
when :CODE
raise LocationParsingError, "We went too far" if compiled.pos > error_column
if compiled.pos > error_column
raise LocationParsingError, "We went too far"
end

if compiled.pos + str.bytesize >= error_column
offset = error_column - compiled.pos
return passed_tokens.map(&:last).join.bytesize + offset
else
raise LocationParsingError unless compiled.scan(str)
unless compiled.scan(str)
raise LocationParsingError, "Couldn't find code snippet"
end
end
when :OPEN
next_tok = source_tokens.first.last
Expand Down
4 changes: 2 additions & 2 deletions actionview/test/template/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_render_runtime_error
assert_equal 6, translated_spot[:first_column]
end

def test_render_location_map_failure
def test_render_location_conditional_append
ex = assert_raises(ActionView::Template::Error) {
@view.render(template: "test/unparseable_runtime_error")
}
Expand All @@ -232,7 +232,7 @@ def test_render_location_map_failure
translating_frame = ActionDispatch::ExceptionWrapper::SourceMapLocation.new(erb_btl, ex.template)
translated_spot = translating_frame.spot(ex.cause)

assert_not_nil translated_spot[:first_column]
assert_equal 8, translated_spot[:first_column]
end
end

Expand Down

0 comments on commit 5513296

Please sign in to comment.