Skip to content

Commit 886f3e7

Browse files
committed
Fix name-parsing.
Handle international characters. Don't violate regex spec.
1 parent 485f812 commit 886f3e7

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/gmail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,7 @@ var Gmail_ = function(localJQuery) {
22122212

22132213

22142214
api.tools.extract_name = function(str) {
2215-
var regex = /[a-z"._-\s]+/gi;
2215+
var regex = /[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF"._\s-]+/gi;
22162216
var matches = (str) ? str.match(regex) : undefined;
22172217

22182218
return (matches && matches[0]) ? matches[0].trim() : undefined;

test/test.parsing.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,36 @@ describe("Current-page parsing", () => {
9797
}
9898
});
9999
});
100+
101+
describe("Name-parsing", () => {
102+
103+
const gmail = new Gmail();
104+
const testName = function(source) {
105+
const result = gmail.tools.extract_name(source + " <>");
106+
assert.deepEqual(result, source);
107+
};
108+
109+
it("handles no spaces in name", () => {
110+
testName("Burt");
111+
});
112+
113+
it("handles spaces in name", () => {
114+
testName("Curt Cobain");
115+
});
116+
117+
it("handles vikings", () => {
118+
testName("Jostein Kjønigsen");
119+
});
120+
121+
it("handles zeh germans", () => {
122+
testName("Frunk Münster");
123+
});
124+
125+
it("handles le frenchies", () => {
126+
testName("Madamoselle Emálie");
127+
});
128+
129+
it("handles mexicans", () => {
130+
testName("Senõr Alapenõ on a stick");
131+
});
132+
});

0 commit comments

Comments
 (0)