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

Use URL-safe version of Base64 for encoding overlay_args #2

Merged
merged 1 commit into from
Nov 4, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/overlastic/concerns/overlay_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def render(*args, **options, &block)
# Force render of overlays without an initiator
request.headers["Overlay-Target"] ||= options.delete(:overlay_target)
request.headers["Overlay-Type"] ||= options.delete(:overlay_type)
request.headers["Overlay-Args"] ||= Base64.encode64(options.delete(:overlay_args).to_json) if options.key?(:overlay_args)
request.headers["Overlay-Args"] ||= Base64.urlsafe_encode64(options.delete(:overlay_args).to_json) if options.key?(:overlay_args)

# If renderable content other than HTML is passed we should avoid returning a stream
avoid_stream = _renderers.excluding(:html).intersection(options.keys).present?
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/overlastic/navigation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def link_to_overlay(name = nil, options = nil, html_options = nil, &block)
options["data"][:overlay_target] = target if target.present?

args = options.delete("overlay_args")
options["data"][:overlay_args] = Base64.encode64(args.to_json) if args.present?
options["data"][:overlay_args] = Base64.urlsafe_encode64(args.to_json) if args.present?

options["target"] = :_blank

Expand All @@ -42,7 +42,7 @@ def link_to_overlay(name = nil, options = nil, html_options = nil, &block)
html_options["data"][:overlay_target] = target if target.present?

args = html_options.delete("overlay_args")
html_options["data"][:overlay_args] = Base64.encode64(args.to_json) if args.present?
html_options["data"][:overlay_args] = Base64.urlsafe_encode64(args.to_json) if args.present?

html_options["target"] = :_blank

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/overlastic/overlays_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def render_overlay(locals = {}, &block)
string = capture(&block)
type = request.headers["Overlay-Type"] || Overlastic.configuration.default_overlay
args_header = request.headers["Overlay-Args"]
overlay_args = JSON.parse(Base64.decode64(request.headers["Overlay-Args"])) if args_header.present?
overlay_args = JSON.parse(Base64.urlsafe_decode64(request.headers["Overlay-Args"])) if args_header.present?
locals.merge! overlay_args.to_h.symbolize_keys

overlastic_tag do
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/navigation_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Overlastic::NavigationHelperTest < ActionView::TestCase
end

test "link_to_overlay with args" do
assert_match "data-overlay-args=\"#{Base64.encode64({ title: "Test dialog" }.to_json)}\"", link_to_overlay("Link", new_dialogs_article_path, overlay_args: { title: "Test dialog" })
assert_match "data-overlay-args=\"#{Base64.urlsafe_encode64({ title: "Test dialog" }.to_json)}\"", link_to_overlay("Link", new_dialogs_article_path, overlay_args: { title: "Test dialog" })
end

test "link_to_overlay without explicit target" do
Expand Down