ruby / uri

URI is a module providing classes to handle Uniform Resource Identifiers
https://ruby.github.io/uri/
Other
79 stars 42 forks source link

::URI::MailTo::EMAIL_REGEXP uses lowercase z for string-end anchor #43

Open foohooboo opened 2 years ago

foohooboo commented 2 years ago
::URI::MailTo::EMAIL_REGEXP == /\A[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z/

Using the Regexp object works just fine. However, using the source in a rails query points out the error in the \z escape squence at the end..

User.where("email ~* ?", ::URI::MailTo::EMAIL_REGEXP) results in the following error:

ActiveRecord::StatementInvalid: PG::InvalidRegularExpression: ERROR: invalid regular expression: invalid escape \ sequence

::URI::MailTo::EMAIL_REGEXP.source == "\\A[a-zA-Z0-9.!\\\#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\\z"

The query is successful when I swap the lowercase z for an uppercase Z.