Skip to content

Commit 693eeb3

Browse files
committed
chore(*): remove manualLowercase & manualUppercase functions
The `manualLowercase` & `manualUppercase` functions were inspired by Google Caja code. Caja is written in Java, though, where problems with `toLowerCase` working differently in Turkish locale are well known[1]. In JavaScript `String#toLowerCase` is defined in the ECMAScript spec and all implementations are required to lowercase I in the same way, regardless of the current locale. Differences may (and do) happen only in `String#toLocaleLowerCase`. Other libraries doing string normalization, like jQuery or DOMPurify don't apply special lowercasing logic in a Turkish environment. Therefore, the `manualLowercase` & `manualUppercase` logic is dead code in AngularJS and can be removed. Also, the `manualLowercase` & `manualUppercase` functions are incomplete; they only lowercase ASCII characters which is different to native `String#toLowerCase`. Since those functions are used in many places in the library, they would break a lot of code. For example, the lowercase filter would not lowercase Ω to ω but leave it as Ω. [1] https://garygregory.wordpress.com/2015/11/03/java-lowercase-conversion-turkey/ Ref angular#11387
1 parent 136a42a commit 693eeb3

File tree

4 files changed

+5
-33
lines changed

4 files changed

+5
-33
lines changed

src/.eslintrc.json

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
"REGEX_STRING_REGEXP" : false,
2929
"lowercase": false,
3030
"uppercase": false,
31-
"manualLowercase": false,
32-
"manualUppercase": false,
3331
"isArrayLike": false,
3432
"forEach": false,
3533
"forEachSorted": false,

src/Angular.js

-27
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
2222
lowercase,
2323
uppercase,
24-
manualLowercase,
25-
manualUppercase,
2624
nodeName_,
2725
isArrayLike,
2826
forEach,
@@ -192,31 +190,6 @@ var lowercase = function(string) {return isString(string) ? string.toLowerCase()
192190
var uppercase = function(string) {return isString(string) ? string.toUpperCase() : string;};
193191

194192

195-
var manualLowercase = function(s) {
196-
/* eslint-disable no-bitwise */
197-
return isString(s)
198-
? s.replace(/[A-Z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) | 32);})
199-
: s;
200-
/* eslint-enable */
201-
};
202-
var manualUppercase = function(s) {
203-
/* eslint-disable no-bitwise */
204-
return isString(s)
205-
? s.replace(/[a-z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) & ~32);})
206-
: s;
207-
/* eslint-enable */
208-
};
209-
210-
211-
// String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish
212-
// locale, for this reason we need to detect this case and redefine lowercase/uppercase methods
213-
// with correct but slower alternatives. See https://github.com/angular/angular.js/issues/11387
214-
if ('i' !== 'I'.toLowerCase()) {
215-
lowercase = manualLowercase;
216-
uppercase = manualUppercase;
217-
}
218-
219-
220193
var
221194
msie, // holds major version number for IE, or NaN if UA is not IE.
222195
jqLite, // delay binding since jQuery could be loaded after us.

test/.eslintrc.json

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343

4444
"lowercase": false,
4545
"uppercase": false,
46-
"manualLowercase": false,
47-
"manualUppercase": false,
4846
"isArrayLike": false,
4947
"forEach": false,
5048
"reverseParams": false,

test/AngularSpec.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ describe('angular', function() {
4444
describe('case', function() {
4545
it('should change case', function() {
4646
expect(lowercase('ABC90')).toEqual('abc90');
47-
expect(manualLowercase('ABC90')).toEqual('abc90');
4847
expect(uppercase('abc90')).toEqual('ABC90');
49-
expect(manualUppercase('abc90')).toEqual('ABC90');
48+
});
49+
50+
it('should change case of non-ASCII letters', function() {
51+
expect(lowercase('Ω')).toEqual('ω');
52+
expect(uppercase('ω')).toEqual('Ω');
5053
});
5154
});
5255

0 commit comments

Comments
 (0)