Skip to content

force_encoding() should be replace with b() for ruby 3.4 or later#446

Open
bsdmad wants to merge 1 commit intoruby-ldap:masterfrom
bsdmad:fix-to_ber-in_true_class-with_b_method
Open

force_encoding() should be replace with b() for ruby 3.4 or later#446
bsdmad wants to merge 1 commit intoruby-ldap:masterfrom
bsdmad:fix-to_ber-in_true_class-with_b_method

Conversation

@bsdmad
Copy link
Copy Markdown

@bsdmad bsdmad commented Apr 11, 2026

Problem

In lib/net/ber/core_ext/true_class.rb, force_encoding() is used.

"\001\001\xFF".force_encoding("ASCII-8BIT")

Therefore it causes a warning like this on ruby 3.4 or later:

/usr/local/bundle/gems/net-ldap-0.20.0/lib/net/ber/core_ext/true_class.rb:9: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)

Solution

I can surpress this warning with b() instead of force_encoding().

  def to_ber
    # http://tools.ietf.org/html/rfc4511#section-5.1
    "\001\001\xFF".b
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant