I get an error when I try to use "^" or "$" in ruby ​​regular expression

Premise

Ruby version is 6.0.0 Rails version is 6.0.3.4 An error has occurred in the above environment.

error contents

The provided regular expression is using multiline anchors (^ or $), which may present a security risk. Did you mean to use \A and \z, or forgot to add the :multiline => true option? (ArgumentError)

Apparently, "^" and "$" are causing an error because there is a security risk.

The solution

It was solved by changing it like ^ → \ A, $ → \ z according to the error statement!

Details about the error

After investigating, it seems that the above error appears in Rails 4.0 or later versions. Security is improving every day!

The reason why "^" and "" are at risk "^" → beginning of line "" → End of line Therefore, unexpected value tolerance occurs when multiple lines are passed.

for that reason "/ A" → the beginning of the character string "/ Z] → end of character string If you change it to, it will be read for each character string, so it is okay to pass multiple lines, so please use "/ A" and "/ z"! It was an error that the instruction came out.

By the way, if you use the ": multiline => true" option, you can also use "^" and "$", so if you are supposed to pass multiple lines, the solution using this option may be better. ..

Recommended Posts

I get an error when I try to use "^" or "$" in ruby ​​regular expression
I get a Ruby version error when I try to start Rails.
I want to display an error message when registering in the database
I want to use arrow notation in Ruby
I get an error when adding a dependency
I want to get the value in Ruby
When I try to run docker-compose, I get the error "Cannot locate specified Dockerfile: Dockerfile"
Summary when trying to use Solr in Java and getting an error (Solr 6.x)
I have a question. I get an error when playing a video in Listview on android.
I found no way to get the error code when I received an exception on Android
Try to implement Yubaba in Ruby
Try an If expression in Java
When I try to put centos in VMware, pane is dead
[Ruby] I want to put an array in a variable. I want to convert to an array
I got an IllegalAccessError when trying to use PowerMock with JUnit
When I try to use the AWS SDK with Ruby + Lambda, `sam local` is messed up.
I tried to create an API to get data from a spreadsheet in Ruby (with service account)
Resolved the error that occurred when trying to use Spark in an environment where Java 8 and Java 11 coexist.
How to get date data in Ruby
Rubocop gets angry when I try to fill zeros (fill 0s) with Ruby
[Android Studio] What to try when you get into error spitting hell
Error when trying to use heroku command
What to do and how to install when an error occurs in DXRuby 1.4.7
I want to get the IP address when connecting to Wi-Fi in Java
I tried to make full use of the CPU core in Ruby
I want to use @Autowired in Servlet
I want to ForEach an array with a Lambda expression in Java
What to do if you get an error when you hit Heroku logs
What to do if you get an "A server is already running." Error when you try to start the rails server
Use hashes well in Ruby to calculate the total amount of an order
When I renew the certificate with CircleCI × fastlane, I get an exit status: 65 error.
Solution that gives an error when trying to connect to DB (MySQL) in Java
Beginner: I get an error on line 30. I don't know where to fix it.
When you want to notify an error somewhere when using graphql-spring-boot in Spring Boot
407 error when trying to access an HTTPS site in Java via an authenticated proxy
I want to send an email in Java.
Second decoction: Try an If expression in Java
When deploying to Heroku, OpenApp causes an error
Try to get redmine API key with ruby
How to solve an Expression Problem in Java
I tried to develop an application in 2 languages
I got an error when I ran rake routes.
[Ruby] How to use the map method. How to process the value of an object and get it by hash or symbol.
Ruby regular expression
I got an error when trying to install sbt to build a Scala development environment
[Ruby] How to use standard output in conditional branching
I want to use Clojure's convenient functions in Kotlin
I get Mysql2 :: Error :: ConnectionError in the production environment
What to do if you get ActiveRecord :: StatementInvalid: Mysql2 :: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near when you try to reset Heroku
I want to use fish shell in Laradock too! !!
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I want to use a little icon in Rails
Try to make an addition program in several languages
I got an error "undefined method` create'" in RSpec
When I bcrypt with node + docker, I got an error
Ruby Regular Expression Extracts from a specific string to a string
A memo to check when you try to use Lombok
[Ruby/Rails] How to generate a password in a regular expression
Notes on how to use regular expressions in Java
How to resolve SSL_connect error in PayPal Ruby SDK
[Ruby on Rails] I want to get the URL of the image saved in Active Storage