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

Scan forward until text tokens match #48294

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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