ECのウェブ担当者のメモ

ECサイトを運営管理している、WEB担当プログラマのメモ

スポンサーリンク

モデルのバリデーションの正規表現の書き方で怒られる

f:id:jun9632:20160311143312p:plain

モデルのバリデーションで以下の様な正規表現を使って書いたら

validates :published_status,
            presence: true,
            format: { with: /^[01]$/}

以下のようなメッセージで怒られました。

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?

どうやら、セキュリティのリスクがあるらしいです。 以下のように置換しないと行けないみたいです。

^ => \A
$ => \z

正解の書き方はこちら

validates :published_status,
            presence: true,
            format: { with: /\A[01]\z/}

注意しましょう。

関連記事

marketing-web.hatenablog.com

marketing-web.hatenablog.com