Repository: tapestry-5 Updated Branches: refs/heads/master 5ee601f49 -> 8c259498f
TAP5-2417: client-side email validator is case sensitive Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/8c259498 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/8c259498 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/8c259498 Branch: refs/heads/master Commit: 8c259498f3e0665ac7949ceaa91ac760c00c733c Parents: 5ee601f Author: Howard M. Lewis Ship <hls...@apache.org> Authored: Tue Dec 23 17:08:18 2014 -0800 Committer: Howard M. Lewis Ship <hls...@apache.org> Committed: Tue Dec 23 17:08:18 2014 -0800 ---------------------------------------------------------------------- .../META-INF/modules/t5/core/validation.coffee | 25 ++++++++++++++++---- .../org/apache/tapestry5/validator/Email.java | 11 +++++---- 2 files changed, 26 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8c259498/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/validation.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/validation.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/validation.coffee index 5cda63c..b44f043 100644 --- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/validation.coffee +++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/validation.coffee @@ -82,6 +82,18 @@ define ["underscore", "./dom", "./events", "./utils", "./messages", "./fields"], return Number canonical + matches = (input, re) -> + groups = input.match re + + # Unlike Java, there isn't an easy way to match the entire string. This + # gets the job done. + + return false if groups is null + + groups[0] is input + + emailRE = new RegExp("[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?") + translate = (field, memo, isInteger) -> try result = parseNumber memo.value, isInteger @@ -133,19 +145,22 @@ define ["underscore", "./dom", "./events", "./utils", "./messages", "./fields"], memo.error = (@attr "data-min-message") or "TOO SMALL" return false + dom.onDocument events.field.validate, "[data-validate-email]", (event, memo) -> + + unless (matches memo.translated, emailRE) + memo.error = (@attr "data-email-message") or "INVALID EMAIL" + return false + dom.onDocument events.field.validate, "[data-validate-regexp]", (event, memo) -> # Cache the compiled regular expression. re = @meta REGEXP_META + unless re re = new RegExp(@attr "data-validate-regexp") @meta REGEXP_META, re - groups = memo.translated.match re - - # Unlike Java, there isn't an easy way to match the entire string. This - # gets the job done. - if (groups is null) or (groups[0] isnt memo.translated) + unless (matches memo.translated, re) memo.error = (@attr "data-regexp-message") or "INVALID" return false http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8c259498/tapestry-core/src/main/java/org/apache/tapestry5/validator/Email.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Email.java b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Email.java index eae9b08..f7b3de0 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/validator/Email.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/validator/Email.java @@ -1,5 +1,3 @@ -// Copyright 2008, 2012, 2014 The Apache Software Foundation -// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -32,7 +30,10 @@ import java.util.regex.Pattern; */ public class Email extends AbstractValidator<Void, String> { - + + // The client-side uses a similar RE, but converts the input to lower case before applying the pattern. + // See validation.coffee. + private static final Pattern PATTERN = Pattern .compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", Pattern.CASE_INSENSITIVE); @@ -53,8 +54,8 @@ public class Email extends AbstractValidator<Void, String> writer.attributes( DataConstants.VALIDATION_ATTRIBUTE, true, - "data-validate-regexp", PATTERN.pattern(), - "data-regexp-message", formatter.toString()); + "data-validate-email", true, + "data-email-message", formatter.toString()); } if (html5Support.isHtml5SupportEnabled()) {