Skip to content

Commit c5122b2

Browse files
author
Nick Frasser
committed
Merge pull request #88 from SoapBox/M-Localization-Fix
Workaround for Chrome `toLowerCase` issue
2 parents f8ded37 + e01a661 commit c5122b2

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/linkify/core/scanner.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,15 @@ S_START.on(/./, makeState(TOKENS.SYM));
125125
*/
126126
let run = function (str) {
127127

128-
let
129-
lowerStr = str.toLowerCase(), // The state machine only looks at lowercase strings
130-
len = str.length,
131-
cursor = 0,
132-
tokens = []; // return value
128+
// The state machine only looks at lowercase strings.
129+
// This selective `toLowerCase` is used because lowercasing the entire
130+
// string causes the length and character position to vary in some in some
131+
// non-English strings. This happens only on V8-based runtimes.
132+
let lowerStr = str.replace(/[A-Z]/g, c => c.toLowerCase());
133+
let len = str.length;
134+
let tokens = []; // return value
135+
136+
var cursor = 0;
133137

134138
// Tokenize the string
135139
while (cursor < len) {

test/spec/linkify/core/parser-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ var tests = [
114114
'The `mailto:` part should not be included in mailto:[email protected]',
115115
[TEXT, EMAIL],
116116
['The `mailto:` part should not be included in mailto:', '[email protected]']
117+
], [
118+
'Bu haritanın verileri Direniş İzleme Grubu\'nun yaptığı Türkiye İşçi Eylemleri haritası ile birleşebilir esasen. https://graphcommons.com/graphs/00af1cd8-5a67-40b1-86e5-32beae436f7c?show=Comments',
119+
[TEXT, URL],
120+
['Bu haritanın verileri Direniş İzleme Grubu\'nun yaptığı Türkiye İşçi Eylemleri haritası ile birleşebilir esasen. ', 'https://graphcommons.com/graphs/00af1cd8-5a67-40b1-86e5-32beae436f7c?show=Comments']
117121
]
118122
];
119123

test/spec/linkify/core/scanner-test.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,33 @@ var tests = [
6161
['500-px', [DOMAIN], ['500-px']],
6262
['-500px', [SYM, DOMAIN], ['-', '500px']],
6363
['500px-', [DOMAIN, SYM], ['500px', '-']],
64-
['123-456', [DOMAIN], ['123-456']]
64+
['123-456', [DOMAIN], ['123-456']],
65+
[
66+
'Direniş İzleme Grubu\'nun',
67+
[DOMAIN, SYM, WS, SYM, DOMAIN, WS, DOMAIN, SYM, DOMAIN],
68+
['Direni', 'ş', ' ', 'İ', 'zleme', ' ', 'Grubu', '\'', 'nun']
69+
]
6570
];
6671

6772
describe('linkify/core/scanner#run()', function () {
6873

6974
function makeTest(test) {
7075
return it('Tokenizes the string "' + test[0] + '"', function () {
76+
7177
var
7278
str = test[0],
7379
types = test[1],
7480
values = test[2],
7581
result = scanner.run(str);
7682

83+
expect(result.map(function (token) {
84+
return token.toString();
85+
})).to.eql(values);
86+
7787
expect(result.map(function (token) {
7888
return token.constructor;
7989
})).to.eql(types);
8090

81-
expect(result.map(function (token) {
82-
return token.toString();
83-
})).to.eql(values);
8491
});
8592
}
8693

0 commit comments

Comments
 (0)