chore(*): remove manualLowercase & manualUppercase functions
The `manualLowercase` & `manualUppercase` functions were inspired by Google Caja code which worked around Java issues 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`. The mirroring of the Java workarounds in Caja was needed due to an old Rhino bug. Rhino is a pre-Nashorn JavaScript interpreter written in Java and it used to delegate `String.prototype.toLowerCase` to `java.lang.String.toLowerCase`. This has since been long fixed. 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/ Closes #15890 Ref #11387
This commit is contained in:
committed by
GitHub
parent
77f26bddf7
commit
5b7e4b4394
@@ -28,8 +28,6 @@
|
||||
"REGEX_STRING_REGEXP" : false,
|
||||
"lowercase": false,
|
||||
"uppercase": false,
|
||||
"manualLowercase": false,
|
||||
"manualUppercase": false,
|
||||
"isArrayLike": false,
|
||||
"forEach": false,
|
||||
"forEachSorted": false,
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
|
||||
lowercase,
|
||||
uppercase,
|
||||
manualLowercase,
|
||||
manualUppercase,
|
||||
nodeName_,
|
||||
isArrayLike,
|
||||
forEach,
|
||||
@@ -148,31 +146,6 @@ var lowercase = function(string) {return isString(string) ? string.toLowerCase()
|
||||
var uppercase = function(string) {return isString(string) ? string.toUpperCase() : string;};
|
||||
|
||||
|
||||
var manualLowercase = function(s) {
|
||||
/* eslint-disable no-bitwise */
|
||||
return isString(s)
|
||||
? s.replace(/[A-Z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) | 32);})
|
||||
: s;
|
||||
/* eslint-enable */
|
||||
};
|
||||
var manualUppercase = function(s) {
|
||||
/* eslint-disable no-bitwise */
|
||||
return isString(s)
|
||||
? s.replace(/[a-z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) & ~32);})
|
||||
: s;
|
||||
/* eslint-enable */
|
||||
};
|
||||
|
||||
|
||||
// String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish
|
||||
// locale, for this reason we need to detect this case and redefine lowercase/uppercase methods
|
||||
// with correct but slower alternatives. See https://github.com/angular/angular.js/issues/11387
|
||||
if ('i' !== 'I'.toLowerCase()) {
|
||||
lowercase = manualLowercase;
|
||||
uppercase = manualUppercase;
|
||||
}
|
||||
|
||||
|
||||
var
|
||||
msie, // holds major version number for IE, or NaN if UA is not IE.
|
||||
jqLite, // delay binding since jQuery could be loaded after us.
|
||||
|
||||
@@ -43,8 +43,6 @@
|
||||
|
||||
"lowercase": false,
|
||||
"uppercase": false,
|
||||
"manualLowercase": false,
|
||||
"manualUppercase": false,
|
||||
"isArrayLike": false,
|
||||
"forEach": false,
|
||||
"reverseParams": false,
|
||||
|
||||
+5
-2
@@ -19,9 +19,12 @@ describe('angular', function() {
|
||||
describe('case', function() {
|
||||
it('should change case', function() {
|
||||
expect(lowercase('ABC90')).toEqual('abc90');
|
||||
expect(manualLowercase('ABC90')).toEqual('abc90');
|
||||
expect(uppercase('abc90')).toEqual('ABC90');
|
||||
expect(manualUppercase('abc90')).toEqual('ABC90');
|
||||
});
|
||||
|
||||
it('should change case of non-ASCII letters', function() {
|
||||
expect(lowercase('Ω')).toEqual('ω');
|
||||
expect(uppercase('ω')).toEqual('Ω');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user