@meetelise/chat 1.77.2 → 1.77.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,6 +27,12 @@ it("accepts emails whose top-level domain is two or more letters", async () => {
27
27
  "o'brien_99@example-mail.io",
28
28
  "jane@例え.テスト",
29
29
  "jane@xn--80ak6aa92e.xn--p1ai",
30
+ "jane@xn--80ak6aa92e.com",
31
+ "jane@пример.рф",
32
+ "jane@example.भारत",
33
+ "jane@example.xn--h2brj9c",
34
+ "jane@xn--e1afmkfd.xn--p1ai",
35
+ "JANE@EXAMPLE.XN--P1AI",
30
36
  "JANE@EXAMPLE.COM",
31
37
  ]) {
32
38
  expect(await flagged(email), email).to.equal(false);
@@ -36,9 +42,19 @@ it("accepts emails whose top-level domain is two or more letters", async () => {
36
42
  it("rejects a one-letter or non-letter top-level domain, and what it rejected before", async () => {
37
43
  for (const email of [
38
44
  "brittney.ciesa+tc17@onmicrosoft.c",
45
+ // A one-letter Cyrillic TLD, as typed and as an email input hands it over (punycode).
46
+ "yury+tc17@onmicrosoft.с",
47
+ "yury+tc17@onmicrosoft.xn--q1a",
48
+ "yury+tc17@onmicrosoft.ю",
49
+ "yury+tc17@onmicrosoft.xn--31a",
50
+ "jane@example.xn--zz",
51
+ "jane@example.xn--com-",
52
+ "jane@example.xn--c0-9lc", // c0м, a digit between two letters
39
53
  "jane@example.c",
40
54
  "jane@example.1",
41
55
  "jane@example.c0m",
56
+ "jane@example.भा", // One letter and a vowel mark.
57
+ "jane@example.\u093eभर", // A leading vowel mark.
42
58
  "jane@example.com.",
43
59
  "jane@example",
44
60
  "jane.example.com",
package/src/utils.ts CHANGED
@@ -5,6 +5,7 @@ import isObject from "lodash/isObject";
5
5
  import transform from "lodash/transform";
6
6
  import addHours from "date-fns/addHours";
7
7
  import isBefore from "date-fns/isBefore";
8
+ import { decode } from "punycode";
8
9
  import { BASE_DOMAIN } from "./globals";
9
10
 
10
11
  export const camelize = <T>(
@@ -95,13 +96,20 @@ export const isValidPhoneNumber = (phoneNumber: string): boolean => {
95
96
  return phoneNumberRegex.test(phoneNumber);
96
97
  };
97
98
 
98
- /**
99
- * Something@domain.tld, where the top-level domain is two or more letters
100
- * (any script) or an IDN's punycode form, so a typo such as "x@y.c" is caught.
101
- */
99
+ /** An email input can return an internationalized TLD in its ASCII (xn--) form. */
102
100
  export const isValidEmail = (email: string): boolean => {
103
- const emailRegex = /^[^\s@]+@[^\s@]+\.(?:\p{L}{2,}|xn--[a-z\d-]+)$/iu;
104
- return emailRegex.test(email);
101
+ const match =
102
+ /^[^\s@]+@[^\s@]+\.(?:([\p{L}\p{M}]+)|xn--([a-z\d-]*[a-z\d]))$/iu.exec(
103
+ email
104
+ );
105
+ if (!match) return false;
106
+ const [, literalTld, encodedTld] = match;
107
+ try {
108
+ const tld = encodedTld ? decode(encodedTld) : literalTld;
109
+ return /^(?:\p{L}\p{M}*){2,}$/u.test(tld);
110
+ } catch {
111
+ return false;
112
+ }
105
113
  };
106
114
 
107
115
  export const isContainingEmail = (message: string): boolean => {