Skip to content

Commit dedbe2a

Browse files
committed
Rails 7.1 Incompatibility: ActionView::Helpers::FormBuilder
Due to Rails monkey patching the Object#to_json method, it is possible for an unassuming object to call the method and trigger a <SystemStackError: stack level too deep> error. https://github.com/rails/rails/blob/v7.1.3.2/activesupport/lib/active_support/core_ext/object/json.rb#L63 We discovered a case where this was caused by an instance of ActionView::Helpers::FormBuilder. We extended MetaRequest::Event#not_encodable? to exclude this class and prevent the recursion.
1 parent e6f9390 commit dedbe2a

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

meta_request/Dockerfile-rails-7.1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM ruby:3.0-alpine
2+
3+
RUN apk add --update --no-cache \
4+
build-base \
5+
curl-dev \
6+
git \
7+
nodejs \
8+
shared-mime-info \
9+
sqlite-dev \
10+
tzdata \
11+
yaml-dev \
12+
yarn \
13+
zlib-dev
14+
15+
RUN mkdir /app /gem
16+
WORKDIR /app
17+
18+
RUN gem update --system 3.5.7
19+
RUN bundle config force_ruby_platform true
20+
RUN gem install rails -v 7.1.3.2
21+
RUN rails new .
22+
23+
COPY . /gem
24+
RUN bundle add meta_request --path /gem
25+
RUN bundle install
26+
27+
COPY res/routes.rb /app/config/
28+
COPY res/dummy_controller.rb /app/app/controllers/
29+
COPY res/dummy /app/app/views/dummy
30+
COPY res/meta_request_test.rb /app/test/integration/
31+
32+
RUN bundle exec rails db:migrate
33+
34+
ENV PARALLEL_WORKERS 1
35+
36+
CMD ["bin/rake"]

meta_request/lib/meta_request/event.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ def sanitize_hash(payload)
6565
end
6666

6767
def not_encodable?(value)
68-
(defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)) ||
69-
(defined?(ActionDispatch) &&
70-
(value.is_a?(ActionDispatch::Request) || value.is_a?(ActionDispatch::Response)))
68+
return true if defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
69+
return true if defined?(ActionDispatch) && (value.is_a?(ActionDispatch::Request) || value.is_a?(ActionDispatch::Response))
70+
return true if defined?(ActionView) && value.is_a?(ActionView::Helpers::FormBuilder)
71+
72+
false
7173
end
7274

7375
# https://gist.github.com/dbenhur/1070399

0 commit comments

Comments
 (0)