| Differences between
and this patch
- a/LayoutTests/fast/forms/ValidityState-typeMismatch-email-expected.txt +39 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-typeMismatch-email-expected.txt_sec1
1
This test aims to check for typeMismatch flag with type=email input fields
2
3
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4
5
6
PASS v.typeMismatch is false
7
PASS v.typeMismatch is false
8
PASS v.typeMismatch is false
9
PASS v.typeMismatch is false
10
PASS v.typeMismatch is false
11
PASS v.typeMismatch is false
12
PASS v.typeMismatch is false
13
PASS v.typeMismatch is false
14
PASS v.typeMismatch is false
15
PASS v.typeMismatch is false
16
PASS v.typeMismatch is false
17
PASS v.typeMismatch is false
18
PASS v.typeMismatch is false
19
PASS v.typeMismatch is true
20
PASS v.typeMismatch is true
21
PASS v.typeMismatch is true
22
PASS v.typeMismatch is true
23
PASS v.typeMismatch is true
24
PASS v.typeMismatch is true
25
PASS v.typeMismatch is true
26
PASS v.typeMismatch is true
27
PASS v.typeMismatch is true
28
PASS v.typeMismatch is true
29
PASS v.typeMismatch is true
30
PASS v.typeMismatch is false
31
PASS v.typeMismatch is false
32
PASS v.typeMismatch is false
33
PASS v.typeMismatch is true
34
PASS v.typeMismatch is true
35
PASS v.typeMismatch is true
36
PASS successfullyParsed is true
37
38
TEST COMPLETE
39
- a/LayoutTests/fast/forms/ValidityState-typeMismatch-email.html +13 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-typeMismatch-email.html_sec1
1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2
<html>
3
<head>
4
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
5
<script src="../../fast/js/resources/js-test-pre.js"></script>
6
</head>
7
<body>
8
<p id="description"></p>
9
<div id="console"></div>
10
<script src="resources/ValidityState-typeMismatch-email.js"></script>
11
<script src="../../fast/js/resources/js-test-post.js"></script>
12
</body>
13
</html>
- a/LayoutTests/fast/forms/resources/ValidityState-typeMismatch-email.js +77 lines
Line 0 a/LayoutTests/fast/forms/resources/ValidityState-typeMismatch-email.js_sec1
1
description("This test aims to check for typeMismatch flag with type=email input fields");
2
3
var i = document.createElement("input");
4
var v = i.validity;
5
6
i.type = "email";
7
shouldBe("v.typeMismatch", "false");
8
9
// VALID SINGLE VALUES
10
i.value = "someone@somewhere.com";
11
shouldBe("v.typeMismatch", "false");
12
i.value = "someone@localhost";
13
shouldBe("v.typeMismatch", "false");
14
i.value = "someone@127.0.0.1";
15
shouldBe("v.typeMismatch", "false");
16
i.value = "a@b";
17
shouldBe("v.typeMismatch", "false");
18
i.value = "a/b@c";
19
shouldBe("v.typeMismatch", "false");
20
i.value = "{}@{}.com";
21
shouldBe("v.typeMismatch", "false");
22
i.value = "ddjk-s-jk@asl-";
23
shouldBe("v.typeMismatch", "false");
24
i.value = "m*'@'!%";
25
shouldBe("v.typeMismatch", "false");
26
i.value = "fasfa@tu!!7n7.ad##0!!!";
27
shouldBe("v.typeMismatch", "false");
28
i.value = "F/s/f/a@feo+re.com";
29
shouldBe("v.typeMismatch", "false");
30
i.value = "some+long+email+address@some+host-weird-/looking.com";
31
shouldBe("v.typeMismatch", "false");
32
i.value = "%@%";
33
shouldBe("v.typeMismatch", "false");
34
35
// INVALID SINGLE VALUES
36
i.value = "@somewhere.com";
37
shouldBe("v.typeMismatch", "true");
38
i.value = ".wooly@example.com";
39
shouldBe("v.typeMismatch", "true");
40
i.value = "wo..oly@example.com";
41
shouldBe("v.typeMismatch", "true");
42
i.value = "pootietang.@example.com";
43
shouldBe("v.typeMismatch", "true");
44
i.value = ".@example.com";
45
shouldBe("v.typeMismatch", "true");
46
i.value = "a space@example.com";
47
shouldBe("v.typeMismatch", "true");
48
i.value = "something@ex..ample.com";
49
shouldBe("v.typeMismatch", "true");
50
i.value = "a\b@c";
51
shouldBe("v.typeMismatch", "true");
52
i.value = "someone@somewhere.com.";
53
shouldBe("v.typeMismatch", "true");
54
i.value = "\"\"test\blah\"\"@example.com";
55
shouldBe("v.typeMismatch", "true");
56
i.value = "\"test\rblah\"@example.com";
57
shouldBe("v.typeMismatch", "true");
58
59
60
// VALID MULTIPLE
61
i.multiple = true;
62
i.value = "someone@somewhere.com,john@doe.com,a@b,a/b@c,ualla@ualla.127"
63
shouldBe("v.typeMismatch", "false");
64
i.value = "some+long+email+address@some+host-weird-/looking.com,F/s/f/a@feo+re.com,m*'@'!%"
65
shouldBe("v.typeMismatch", "false");
66
i.value= ",,,,,,,,,,,";
67
shouldBe("v.typeMismatch", "false");
68
69
// INVALID MULTIPLE (true on the first invalid occurrence)
70
i.value = "someone@somewhere.com,john@doe..com,a@b,a/b@c,ualla@ualla.127"
71
shouldBe("v.typeMismatch", "true");
72
i.value = "some+long+email+address@some+host:weird-/looking.com,F/s/f/a@feo+re.com,,m*'@'!%"
73
shouldBe("v.typeMismatch", "true");
74
i.value= ",,,,,,,,, ,,";
75
shouldBe("v.typeMismatch", "true");
76
77
var successfullyParsed = true;
- a/WebCore/html/ValidityState.cpp +50 lines
Lines 23-36 a/WebCore/html/ValidityState.cpp_sec1
23
#include "config.h"
23
#include "config.h"
24
#include "ValidityState.h"
24
#include "ValidityState.h"
25
25
26
#include "HTMLInputElement.h"
27
#include "HTMLNames.h"
28
#include "RegularExpression.h"
29
#include <wtf/StdLibExtras.h>
30
31
#define RFC5322_DOTATOMTEXT "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*"
32
26
namespace WebCore {
33
namespace WebCore {
27
34
35
using namespace HTMLNames;
36
28
ValidityState::ValidityState(HTMLFormControlElement* parent)
37
ValidityState::ValidityState(HTMLFormControlElement* parent)
29
    : m_control(parent)
38
    : m_control(parent)
30
{
39
{
31
    ASSERT(parent);
40
    ASSERT(parent);
32
}
41
}
33
42
43
bool ValidityState::typeMismatch()
44
{
45
    if (!control()->hasTagName(inputTag))
46
        return false;
47
48
    HTMLInputElement* input = static_cast<HTMLInputElement*>(control());
49
    String value = input->value();
50
51
    if (value.isEmpty())
52
        return false;
53
54
    if (input->inputType() == HTMLInputElement::EMAIL) {
55
        if (!input->multiple())
56
            return !isValidEmailAddress(value);
57
            
58
        Vector<String> email_list;
59
        value.split(',', email_list);
60
        for (unsigned i = 0; i < email_list.size(); ++i)
61
            if (!isValidEmailAddress(email_list[i]))
62
                return true;
63
    }
64
65
    return false;
66
}
67
34
bool ValidityState::valid()
68
bool ValidityState::valid()
35
{
69
{
36
    bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() ||
70
    bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() ||
Lines 39-42 bool ValidityState::valid() a/WebCore/html/ValidityState.cpp_sec2
39
    return !someError;
73
    return !someError;
40
}
74
}
41
75
76
bool ValidityState::isValidEmailAddress(String& email)
77
{
78
    if (email.isEmpty())
79
        return false;
80
81
    DEFINE_STATIC_LOCAL(AtomicString, dotAtomText, (RFC5322_DOTATOMTEXT));
82
    DEFINE_STATIC_LOCAL(AtomicString, emailPattern, (dotAtomText + "@" + dotAtomText));
83
    DEFINE_STATIC_LOCAL(RegularExpression, regExp, (emailPattern, TextCaseInsensitive));
84
85
    int matchLength = 0;
86
    int emailLength = email.length();
87
    int matchOffset = regExp.match(email, 0, &matchLength);
88
89
    return matchOffset == 0 && matchLength == emailLength;
90
}
91
42
} // namespace
92
} // namespace
- a/WebCore/html/ValidityState.h -1 / +2 lines
Lines 41-47 namespace WebCore { a/WebCore/html/ValidityState.h_sec1
41
        void setCustomErrorMessage(const String& message) { m_customErrorMessage = message; }
41
        void setCustomErrorMessage(const String& message) { m_customErrorMessage = message; }
42
42
43
        bool valueMissing() { return control()->valueMissing(); }
43
        bool valueMissing() { return control()->valueMissing(); }
44
        bool typeMismatch() { return false; }
44
        bool typeMismatch();
45
        bool patternMismatch() { return control()->patternMismatch(); }
45
        bool patternMismatch() { return control()->patternMismatch(); }
46
        bool tooLong() { return false; }
46
        bool tooLong() { return false; }
47
        bool rangeUnderflow() { return false; }
47
        bool rangeUnderflow() { return false; }
Lines 52-57 namespace WebCore { a/WebCore/html/ValidityState.h_sec2
52
52
53
    private:
53
    private:
54
        ValidityState(HTMLFormControlElement*);
54
        ValidityState(HTMLFormControlElement*);
55
        bool isValidEmailAddress(String&);
55
        HTMLFormControlElement* m_control;
56
        HTMLFormControlElement* m_control;
56
        String m_customErrorMessage;
57
        String m_customErrorMessage;
57
    };
58
    };

Return to Bug 27457