Skip to content

Commit c4603c1

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 3a2aea7 commit c4603c1

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

150148

151-
var manualLowercase = function(s) {
152-
/* eslint-disable no-bitwise */
153-
return isString(s)
154-
? s.replace(/[A-Z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) | 32);})
155-
: s;
156-
/* eslint-enable */
157-
};
158-
var manualUppercase = function(s) {
159-
/* eslint-disable no-bitwise */
160-
return isString(s)
161-
? s.replace(/[a-z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) & ~32);})
162-
: s;
163-
/* eslint-enable */
164-
};
165-
166-
167-
// String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish
168-
// locale, for this reason we need to detect this case and redefine lowercase/uppercase methods
169-
// with correct but slower alternatives. See https://github.com/angular/angular.js/issues/11387
170-
if ('i' !== 'I'.toLowerCase()) {
171-
lowercase = manualLowercase;
172-
uppercase = manualUppercase;
173-
}
174-
175-
176149
var
177150
msie, // holds major version number for IE, or NaN if UA is not IE.
178151
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)