Changeset 49508 in webkit


Ignore:
Timestamp:
Oct 13, 2009 1:53:12 PM (15 years ago)
Author:
eric@webkit.org
Message:

2009-10-13 Michelangelo De Simone <micdesim@gmail.com>

Reviewed by Adam Barth.

https://bugs.webkit.org/show_bug.cgi?id=27457
Test case for static email validation on type=email input elements as
per HTML5 specs:
http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state

  • fast/forms/ValidityState-typeMismatch-email-expected.txt: Added.
  • fast/forms/ValidityState-typeMismatch-email.html: Added.
  • fast/forms/resources/ValidityState-typeMismatch-email.js: Added. ():

2009-10-13 Michelangelo De Simone <micdesim@gmail.com>

Reviewed by Adam Barth.

https://bugs.webkit.org/show_bug.cgi?id=27457
Added support for static validation on type=email input elements as per
HTML5 specs:
http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state

Test: fast/forms/ValidityState-typeMismatch-email.html

  • html/ValidityState.cpp: (WebCore::ValidityState::typeMismatch): ValidityState.typeMismatch performs validation on type=email input elements now. (WebCore::ValidityState::isValidEmailAddress): simple validation method
  • html/ValidityState.h:
Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r49507 r49508  
     12009-10-13  Michelangelo De Simone  <micdesim@gmail.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=27457
     6        Test case for static email validation on type=email input elements as
     7        per HTML5 specs:
     8        http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state
     9
     10        * fast/forms/ValidityState-typeMismatch-email-expected.txt: Added.
     11        * fast/forms/ValidityState-typeMismatch-email.html: Added.
     12        * fast/forms/resources/ValidityState-typeMismatch-email.js: Added.
     13        ():
     14
    1152009-10-13  Dmitry Titov  <dimich@chromium.org>
    216
  • trunk/WebCore/ChangeLog

    r49507 r49508  
     12009-10-13  Michelangelo De Simone  <micdesim@gmail.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=27457
     6        Added support for static validation on type=email input elements as per
     7        HTML5 specs:
     8        http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state
     9
     10        Test: fast/forms/ValidityState-typeMismatch-email.html
     11
     12        * html/ValidityState.cpp:
     13        (WebCore::ValidityState::typeMismatch): ValidityState.typeMismatch
     14        performs validation on type=email input elements now.
     15        (WebCore::ValidityState::isValidEmailAddress): simple validation method
     16        * html/ValidityState.h:
     17
    1182009-10-13  Dmitry Titov  <dimich@chromium.org>
    219
  • trunk/WebCore/html/ValidityState.cpp

    r49199 r49508  
    2727#include "HTMLNames.h"
    2828#include "KURL.h"
     29#include "RegularExpression.h"
     30#include <wtf/StdLibExtras.h>
     31
     32#define EMAIL_LOCALPART "[a-z0-9!#$%&'*+/=?^_`{|}~.-]+"
     33#define EMAIL_DOMAINPART "[a-z0-9-]+(\\.[a-z0-9-]+)+"
     34#define EMAIL_PATTERN EMAIL_LOCALPART "@" EMAIL_DOMAINPART
    2935
    3036namespace WebCore {
     
    5662    case HTMLInputElement::URL:
    5763        return !KURL(KURL(), value).isValid();
     64    case HTMLInputElement::EMAIL:
     65    {
     66        if (!input->multiple())
     67            return !isValidEmailAddress(value);
     68           
     69        Vector<String> email_list;
     70        value.split(',', email_list);
     71        for (unsigned i = 0; i < email_list.size(); ++i)
     72            if (!isValidEmailAddress(email_list[i]))
     73                return true;
     74
     75        return false;
     76    }
    5877    default:
    5978        return false;
     
    96115}
    97116
     117bool ValidityState::isValidEmailAddress(const String& email)
     118{
     119    if (email.isEmpty())
     120        return false;
     121
     122    DEFINE_STATIC_LOCAL(AtomicString, emailPattern, (EMAIL_PATTERN));
     123    DEFINE_STATIC_LOCAL(RegularExpression, regExp, (emailPattern, TextCaseInsensitive));
     124
     125    int matchLength = 0;
     126    int emailLength = email.length();
     127    int matchOffset = regExp.match(email, 0, &matchLength);
     128
     129    return matchOffset == 0 && matchLength == emailLength;
     130}
     131
    98132} // namespace
  • trunk/WebCore/html/ValidityState.h

    r49199 r49508  
    5757
    5858        static bool isValidColorString(const String&);
     59        bool isValidEmailAddress(const String&);
    5960    };
    6061
Note: See TracChangeset for help on using the changeset viewer.