Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Vos RegExps sont fausses !     Simon COURTOIS - @happynoff
^...$
^...$class User < ActiveRecord::Base  attr_accessible :email  validates :email,            presence: true,            uniq...
^...$toto@exemple.fr   ✔totoexemple.fr    ✗hellototo@exemple.fr   ✔hello
^...$
ˆ...$http://ruby-doc.org/core-1.9.3/Regexp.html  Anchors  ^   - Matches beginning of line  $   - Matches end of line
^...$➜ hello➜ totoexemple.fr➜ hello
A...Zhttp://ruby-doc.org/core-1.9.3/Regexp.html  Anchors  ^   - Matches beginning of line  $   - Matches end of line  A - ...
A...Zclass User < ActiveRecord::Base  attr_accessible :email  validates :email,            presence: true,            uniq...
A...Zclass User < ActiveRecord::Base  attr_accessible :email  validates :email,            presence: true,            uniq...
A...Ztoto@exemple.fr   ✔totoexemple.fr    ✗hellototoexemple.fr    ✗hello
A...Z
Merci !Simon COURTOIS - @happynoff
Upcoming SlideShare
Loading in …5
×

Vos Regexps sont fausses !

464 views

Published on

Je montre ici une simple mesure de sécurité concernant les expressions régulières de validation.

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

Vos Regexps sont fausses !

  1. 1. Vos RegExps sont fausses ! Simon COURTOIS - @happynoff
  2. 2. ^...$
  3. 3. ^...$class User < ActiveRecord::Base attr_accessible :email validates :email, presence: true, uniqueness: true, format: { with: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/i }endhttp://www.regular-expressions.info/email.html
  4. 4. ^...$toto@exemple.fr ✔totoexemple.fr ✗hellototo@exemple.fr ✔hello
  5. 5. ^...$
  6. 6. ˆ...$http://ruby-doc.org/core-1.9.3/Regexp.html Anchors ^ - Matches beginning of line $ - Matches end of line
  7. 7. ^...$➜ hello➜ totoexemple.fr➜ hello
  8. 8. A...Zhttp://ruby-doc.org/core-1.9.3/Regexp.html Anchors ^ - Matches beginning of line $ - Matches end of line A - Matches beginning of string Z - Matches end of string
  9. 9. A...Zclass User < ActiveRecord::Base attr_accessible :email validates :email, presence: true, uniqueness: true, format: { with: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/i }end
  10. 10. A...Zclass User < ActiveRecord::Base attr_accessible :email validates :email, presence: true, uniqueness: true, format: { with: /A[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}Z/i }end
  11. 11. A...Ztoto@exemple.fr ✔totoexemple.fr ✗hellototoexemple.fr ✗hello
  12. 12. A...Z
  13. 13. Merci !Simon COURTOIS - @happynoff

×