Skip to content

Use `Kernel.format` to avoid conflicts with ViewComponent's `format`

Peter Leitzen requested to merge pl-safe-format-kernel into master

What does this MR do and why?

See !119942 (comment 1393695898)

How to set up and validate locally

bin/rspec spec/helpers/safe_format_helper_spec.rb
...
Finished in 6.39 seconds (files took 11.2 seconds to load)
12 examples, 0 failures

git checkout master -- app/helpers/safe_format_helper.rb
bin/rspec spec/helpers/safe_format_helper_spec.rb

...

Failures:

  1) SafeFormatHelper#safe_format with a view component safetly formats
     Failure/Error:
       format(
         html_escape(format),
         args.transform_values { |value| html_escape(value) }
       ).html_safe

     ArgumentError:
       wrong number of arguments (given 2, expected 0)
     # ./app/helpers/safe_format_helper.rb:18:in `safe_format'
     # ./spec/helpers/safe_format_helper_spec.rb:47:in `call'
     # ./spec/helpers/safe_format_helper_spec.rb:53:in `block (4 levels) in <top (required)>'
     # ./spec/spec_helper.rb:423:in `block (3 levels) in <top (required)>'
     # ./spec/support/sidekiq_middleware.rb:18:in `with_sidekiq_server_middleware'
     # ./spec/spec_helper.rb:415:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:411:in `block (3 levels) in <top (required)>'
     # ./lib/gitlab/application_context.rb:61:in `with_raw_context'
     # ./spec/spec_helper.rb:411:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:242:in `block (2 levels) in <top (required)>'
     # ./spec/support/system_exit_detected.rb:7:in `block (2 levels) in <main>'
     # ./spec/support/database/prevent_cross_joins.rb:108:in `block (3 levels) in <main>'
     # ./spec/support/database/prevent_cross_joins.rb:62:in `with_cross_joins_prevented'
     # ./spec/support/database/prevent_cross_joins.rb:108:in `block (2 levels) in <main>'

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports

Loading