Skip to content

Commit 4c9acd4

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 837acd1 commit 4c9acd4

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,
@@ -149,31 +147,6 @@ var lowercase = function(string) {return isString(string) ? string.toLowerCase()
149147
var uppercase = function(string) {return isString(string) ? string.toUpperCase() : string;};
150148

151149

152-
var manualLowercase = function(s) {
153-
/* eslint-disable no-bitwise */
154-
return isString(s)
155-
? s.replace(/[A-Z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) | 32);})
156-
: s;
157-
/* eslint-enable */
158-
};
159-
var manualUppercase = function(s) {
160-
/* eslint-disable no-bitwise */
161-
return isString(s)
162-
? s.replace(/[a-z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) & ~32);})
163-
: s;
164-
/* eslint-enable */
165-
};
166-
167-
168-
// String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish
169-
// locale, for this reason we need to detect this case and redefine lowercase/uppercase methods
170-
// with correct but slower alternatives. See https://github.com/angular/angular.js/issues/11387
171-
if ('i' !== 'I'.toLowerCase()) {
172-
lowercase = manualLowercase;
173-
uppercase = manualUppercase;
174-
}
175-
176-
177150
var
178151
msie, // holds major version number for IE, or NaN if UA is not IE.
179152
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
@@ -19,9 +19,12 @@ describe('angular', function() {
1919
describe('case', function() {
2020
it('should change case', function() {
2121
expect(lowercase('ABC90')).toEqual('abc90');
22-
expect(manualLowercase('ABC90')).toEqual('abc90');
2322
expect(uppercase('abc90')).toEqual('ABC90');
24-
expect(manualUppercase('abc90')).toEqual('ABC90');
23+
});
24+
25+
it('should change case of non-ASCII letters', function() {
26+
expect(lowercase('Ω')).toEqual('ω');
27+
expect(uppercase('ω')).toEqual('Ω');
2528
});
2629
});
2730

0 commit comments

Comments
 (0)