Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Remove angular.uppercase/lowercase #15445

Merged
merged 1 commit into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,7 @@ function isValidObjectMaxDepth(maxDepth) {
}

/**
* @ngdoc function
* @name angular.lowercase
* @module ng
* @kind function
*
* @deprecated
* sinceVersion="1.5.0"
* removeVersion="1.7.0"
* Use [String.prototype.toLowerCase](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase) instead.
* @private
*
* @description Converts the specified string to lowercase.
* @param {string} string String to be converted to lowercase.
Expand All @@ -190,15 +182,7 @@ function isValidObjectMaxDepth(maxDepth) {
var lowercase = function(string) {return isString(string) ? string.toLowerCase() : string;};

/**
* @ngdoc function
* @name angular.uppercase
* @module ng
* @kind function
*
* @deprecated
* sinceVersion="1.5.0"
* removeVersion="1.7.0"
* Use [String.prototype.toUpperCase](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase) instead.
* @private
*
* @description Converts the specified string to uppercase.
* @param {string} string String to be converted to uppercase.
Expand Down
6 changes: 3 additions & 3 deletions src/AngularPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ function publishExternalAPI(angular) {
'isArray': isArray,
'version': version,
'isDate': isDate,
'lowercase': lowercase,
'uppercase': uppercase,
'callbacks': {$$counter: 0},
'getTestability': getTestability,
'reloadWithDebugInfo': reloadWithDebugInfo,
'$$minErr': minErr,
'$$csp': csp,
'$$encodeUriSegment': encodeUriSegment,
'$$encodeUriQuery': encodeUriQuery,
'$$stringify': stringify
'$$lowercase': lowercase,
'$$stringify': stringify,
'$$uppercase': uppercase
});

angularModule = setupModuleLoader(window);
Expand Down
4 changes: 2 additions & 2 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2072,13 +2072,13 @@ function MockXhr() {
var header = this.$$respHeaders[name];
if (header) return header;

name = angular.lowercase(name);
name = angular.$$lowercase(name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep the service, even as a private one? String.prototype methods should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that angular.lowercase / uppercase is overwritten with a manual version that handles Turkish i:

angular.js/src/Angular.js

Lines 210 to 232 in 19bc521

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;
}

So in core, we use a "safe" version. But we don't want anyone else to use it? I guess we don't want anyone to use the special version when usually the prototype functions are enough.

Copy link
Member

@mgol mgol Mar 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jQuery doesn't have any logic like that in its lowercasing and we haven't heard any complaints related to Turkish keyboards. Given jQuery's popularity I'd assume this code is no longer needed, especially that ES5 (!) mandates no such differences so I doubt any relatively recent browser would still have whatever issue existed (if it ever has).

I'd remove the "manual" functions as well. This is security-related code, though, so a this requires some consideration, though.

header = this.$$respHeaders[name];
if (header) return header;

header = undefined;
angular.forEach(this.$$respHeaders, function(headerVal, headerName) {
if (!header && angular.lowercase(headerName) === name) header = headerVal;
if (!header && angular.$$lowercase(headerName) === name) header = headerVal;
});
return header;
};
Expand Down
2 changes: 1 addition & 1 deletion src/ngSanitize/sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function $SanitizeProvider() {
extend = angular.extend;
forEach = angular.forEach;
isDefined = angular.isDefined;
lowercase = angular.lowercase;
lowercase = angular.$$lowercase;
noop = angular.noop;

htmlParser = htmlParserImpl;
Expand Down
2 changes: 1 addition & 1 deletion src/ngTouch/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var ngTouch = angular.module('ngTouch', []);
ngTouch.provider('$touch', $TouchProvider);

function nodeName_(element) {
return angular.lowercase(element.nodeName || (element[0] && element[0].nodeName));
return angular.$$lowercase(element.nodeName || (element[0] && element[0].nodeName));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11353,7 +11353,7 @@ describe('$compile', function() {
element = $compile('<iframe srcdoc="{{html}}"></iframe>')($rootScope);
$rootScope.html = $sce.trustAsHtml('<div onclick="">hello</div>');
$rootScope.$digest();
expect(angular.lowercase(element.attr('srcdoc'))).toEqual('<div onclick="">hello</div>');
expect(lowercase(element.attr('srcdoc'))).toEqual('<div onclick="">hello</div>');
}));
});
}
Expand Down
20 changes: 10 additions & 10 deletions test/ng/directive/ngBindSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@ describe('ngBind*', function() {
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
$rootScope.html = '<div onclick="">hello</div>';
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('<div onclick="">hello</div>');
expect(lowercase(element.html())).toEqual('<div onclick="">hello</div>');
}));

it('should update html', inject(function($rootScope, $compile, $sce) {
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
$rootScope.html = 'hello';
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('hello');
expect(lowercase(element.html())).toEqual('hello');
$rootScope.html = 'goodbye';
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('goodbye');
expect(lowercase(element.html())).toEqual('goodbye');
}));

it('should one-time bind if the expression starts with two colons', inject(function($rootScope, $compile) {
Expand Down Expand Up @@ -220,17 +220,17 @@ describe('ngBind*', function() {
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
$rootScope.html = $sce.trustAsHtml('<div onclick="">hello</div>');
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('<div onclick="">hello</div>');
expect(lowercase(element.html())).toEqual('<div onclick="">hello</div>');
}));

it('should update html', inject(function($rootScope, $compile, $sce) {
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
$rootScope.html = $sce.trustAsHtml('hello');
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('hello');
expect(lowercase(element.html())).toEqual('hello');
$rootScope.html = $sce.trustAsHtml('goodbye');
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('goodbye');
expect(lowercase(element.html())).toEqual('goodbye');
}));

it('should not cause infinite recursion for trustAsHtml object watches',
Expand All @@ -243,7 +243,7 @@ describe('ngBind*', function() {
return $sce.trustAsHtml('<div onclick="">hello</div>');
};
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('<div onclick="">hello</div>');
expect(lowercase(element.html())).toEqual('<div onclick="">hello</div>');
}));

it('should handle custom $sce objects', function() {
Expand All @@ -266,10 +266,10 @@ describe('ngBind*', function() {
var html = 'hello';
$rootScope.getHtml = function() { return $sce.trustAsHtml(html); };
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('hello');
expect(lowercase(element.html())).toEqual('hello');
html = 'goodbye';
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('goodbye');
expect(lowercase(element.html())).toEqual('goodbye');
});
});

Expand All @@ -280,7 +280,7 @@ describe('ngBind*', function() {
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
$rootScope.html = '<div onclick="">hello</div>';
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('<div>hello</div>');
expect(lowercase(element.html())).toEqual('<div>hello</div>');
}));
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/ngSanitize/directive/ngBindHtmlSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('ngBindHtml', function() {
var element = $compile('<div ng-bind-html="html"></div>')($rootScope);
$rootScope.html = '<div unknown>hello</div>';
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('<div>hello</div>');
expect(lowercase(element.html())).toEqual('<div>hello</div>');
}));


Expand All @@ -18,11 +18,11 @@ describe('ngBindHtml', function() {
angular.forEach([null, undefined, ''], function(val) {
$rootScope.html = 'some val';
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('some val');
expect(lowercase(element.html())).toEqual('some val');

$rootScope.html = val;
$rootScope.$digest();
expect(angular.lowercase(element.html())).toEqual('');
expect(lowercase(element.html())).toEqual('');
});
}));
});