menu

Search By Label

Did you know that in Ruby 3.1.3 and prior some regexps could take a long time to process?

Don't believe me? Try running this in a 3.1.3 irb console:

`/^a*b?a*$/ =~ "a" * 50000 + "x"`

Your system will halt for like 10 seconds before returning no matches. This is the basis for ReDoS (Regexp Denial of Service) attacks.

Thankfully, Ruby 3.2.0 has fixed this and the same regexp gets resolved in 0.003 seconds. They also added a `Regex.timeout` global option which would prevent your app from falling victim to ReDoS attacks!

Yesterday I implemented gzip request support in a project and noticed there are no gems for that. There's `Rack::Deflater` but that's for responses, not requests. Apparently, incoming gzipped payloads are uncommon. 🤷‍♀

Maybe an opportunity to write a new gem? 🤔

In Ruby, the .empty? method is used to check whether a data structure, such as a string, array, or hash, is empty. It returns true if the object it is called on contains no elements or characters, and false otherwise. 

Example:

# Strings 
empty_string = "" 
non_empty_string = "Hello, world!"empty_string.empty? # => true 
non_empty_string.empty? # => false# Arrays 
empty_array = [] 
non_empty_array = [1, 2, 3]empty_array.empty? # => true 
non_empty_array.empty? # => false# Hashes 
empty_hash = {} 
non_empty_hash = { name: "John", age: 30 }empty_hash.empty? # => true 
non_empty_hash.empty? # => false