Skip to content

Commit 2274219

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 b7d396b commit 2274219

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

149147

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