Skip to content

Commit 90cce04

Browse files
fix: Replace deprecated String.prototype.substr() (#1242)
.substr() is deprecated so we replace it with functions which work similarily but aren't deprecated Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
1 parent 964f81a commit 90cce04

13 files changed

Lines changed: 41 additions & 41 deletions

‎js/app/controllers/calendarlistcontroller.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'Ha
9191
let name = splittedICal.name || url;
9292

9393
if (name.length > 100) {
94-
name = name.substr(0, 100);
94+
name = name.slice(0, 100);
9595
}
9696

9797
CalendarService.createWebCal(name, color, url)

‎js/app/controllers/recurrencecontroller.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ app.controller('RecurrenceController', function($scope) {
128128
if(angular.isDefined($scope.properties.rrule.byday)) {
129129
if($scope.custom.freq === 'MONTHLY') {
130130
$scope.selected_month_recurrence = 'WEEK';
131-
$scope.custom.interval = parseInt($scope.properties.rrule.byday[0].substr(0, $scope.properties.rrule.byday[0].length - 2));
132-
$scope.custom.weekday = $scope.properties.rrule.byday[0].substr($scope.properties.rrule.byday[0].length - 2, $scope.properties.rrule.byday[0].length - 1);
131+
$scope.custom.interval = parseInt($scope.properties.rrule.byday[0].slice(0, -2));
132+
$scope.custom.weekday = $scope.properties.rrule.byday[0].slice(-2);
133133
}
134134
else {
135135
angular.forEach($scope.properties.rrule.byday, function(value) {
@@ -226,4 +226,4 @@ app.controller('RecurrenceController', function($scope) {
226226
}
227227
});
228228
};
229-
});
229+
});

‎js/app/factory/calendarFactory.js‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ app.service('CalendarFactory', function($window, DavClient, Calendar, WebCal, co
5959
// but some browsers can't parse that *cough cough* Safari 9 *cough cough*
6060
// Safari 10 seems to support this though
6161
if (colorProp.length === 9) {
62-
return colorProp.substr(0,7);
62+
return colorProp.slice(0,7);
6363
}
6464
return colorProp;
6565
} else {
@@ -114,7 +114,7 @@ app.service('CalendarFactory', function($window, DavClient, Calendar, WebCal, co
114114
const index = owner.indexOf('/remote.php/dav/principals/users/');
115115
if (index !== -1) {
116116
// '/remote.php/dav/principals/users/'.length === 33
117-
return owner.substr(index + 33);
117+
return owner.slice(index + 33);
118118
}
119119
}
120120

@@ -148,9 +148,9 @@ app.service('CalendarFactory', function($window, DavClient, Calendar, WebCal, co
148148
let displayName = share.getElementsByTagNameNS(DavClient.NS_OWNCLOUD, 'common-name');
149149
if (displayName.length === 0) {
150150
if (href.startsWith(SHARE_USER_PREFIX)) {
151-
displayName = href.substr(SHARE_USER_PREFIX.length);
151+
displayName = href.slice(SHARE_USER_PREFIX.length);
152152
} else {
153-
displayName = href.substr(SHARE_GROUP_PREFIX.length);
153+
displayName = href.slice(SHARE_GROUP_PREFIX.length);
154154
}
155155
} else {
156156
displayName = displayName[0].textContent;
@@ -166,21 +166,21 @@ app.service('CalendarFactory', function($window, DavClient, Calendar, WebCal, co
166166
writable = writable.length !== 0;
167167

168168
if (href.startsWith(SHARE_USER_PREFIX)) {
169-
if (href.substr(SHARE_USER_PREFIX.length) === owner) {
169+
if (href.slice(SHARE_USER_PREFIX.length) === owner) {
170170
// don't overwrite already present displayname
171171
if (!ownerDisplayname) {
172172
ownerDisplayname = displayName;
173173
}
174174
} else {
175175
shares.users.push({
176-
id: href.substr(SHARE_USER_PREFIX.length),
176+
id: href.slice(SHARE_USER_PREFIX.length),
177177
displayname: displayName,
178178
writable: writable
179179
});
180180
}
181181
} else if (href.startsWith(SHARE_GROUP_PREFIX)) {
182182
shares.groups.push({
183-
id: href.substr(SHARE_GROUP_PREFIX.length),
183+
id: href.slice(SHARE_GROUP_PREFIX.length),
184184
displayname: displayName,
185185
writable: writable
186186
});
@@ -219,12 +219,12 @@ app.service('CalendarFactory', function($window, DavClient, Calendar, WebCal, co
219219
if (angular.isDefined(props['{' + DavClient.NS_CALENDARSERVER + '}publish-url'])) {
220220
published = true;
221221
let publishURL = props['{' + DavClient.NS_CALENDARSERVER + '}publish-url'][0].textContent;
222-
if (publishURL.substr(-1) === '/') {
223-
publishURL = publishURL.substr(0, publishURL.length - 1);
222+
if (publishURL.slice(-1) === '/') {
223+
publishURL = publishURL.slice(0, -1);
224224
}
225225

226226
const lastIndexOfSlash = publishURL.lastIndexOf('/');
227-
publicToken = publishURL.substr(lastIndexOfSlash + 1);
227+
publicToken = publishURL.slice(lastIndexOfSlash + 1);
228228
}
229229

230230
return [published, publicToken];
@@ -299,7 +299,7 @@ app.service('CalendarFactory', function($window, DavClient, Calendar, WebCal, co
299299
}
300300

301301
const slashIndex = userPrincipal.lastIndexOf('/');
302-
return userPrincipal.substr(slashIndex + 1);
302+
return userPrincipal.slice(slashIndex + 1);
303303
};
304304

305305
/**

‎js/app/filters/attendeefilter.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ app.filter('attendeeFilter', function() {
3030
} else if (typeof attendee.parameters === 'object' && typeof attendee.parameters.cn === 'string') {
3131
return attendee.parameters.cn;
3232
} else if (typeof attendee.value === 'string' && attendee.value.startsWith('MAILTO:')) {
33-
return attendee.value.substr(7);
33+
return attendee.value.slice(7);
3434
} else {
3535
return attendee.value || '';
3636
}

‎js/app/models/calendarListItemModel.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ app.factory('CalendarListItem', function($rootScope, $window, Calendar, WebCal,
181181
const searchFor = '(' + context.calendar.owner + ')';
182182
const lastIndexOf = context.calendar.displayname.lastIndexOf(searchFor);
183183

184-
return context.calendar.displayname.substr(0, lastIndexOf - 1);
184+
return context.calendar.displayname.slice(0, lastIndexOf > 0 ? lastIndexOf - 1 : 0);
185185
};
186186

187187
//Properties for ng-model of calendar editor

‎js/app/models/veventModel.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ app.factory('VEvent', function(TimezoneService, FcEvent, SimpleEvent, ICalFactor
329329
var dateType = /[^:]*/.exec(el)[0];
330330
var icsDate = null;
331331

332-
if (findTypes.indexOf(dateType) >= 0 && el.trim().substr(-3) === 'T::') { // is date without time
332+
if (findTypes.indexOf(dateType) >= 0 && el.trim().slice(-3) === 'T::') { // is date without time
333333
icsDate = el.replace(/[^0-9]/g, '');
334334
ics = ics.replace(el, dateType + ';VALUE=DATE:' + icsDate);
335335
}

‎js/app/service/davClient.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ app.service('DavClient', function($window) {
4949
* @returns {string}
5050
*/
5151
client.buildUrl = function(path) {
52-
if (path.substr(0,1) !== '/') {
52+
if (path.slice(0,1) !== '/') {
5353
path = '/' + path;
5454
}
5555

‎js/app/service/hashService.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ app.service('HashService', function ($location) {
3636
}
3737

3838
if (hash.startsWith('#')) {
39-
hash = hash.substr(1);
39+
hash = hash.slice(1);
4040
}
4141
if (hash.startsWith('/')) {
42-
hash = hash.substr(1);
42+
hash = hash.slice(1);
4343
}
4444

4545

@@ -57,9 +57,9 @@ app.service('HashService', function ($location) {
5757
}
5858

5959
const questionMarkPosition = hash.indexOf('?');
60-
context.hashId = hash.substr(0, questionMarkPosition);
60+
context.hashId = hash.slice(0, questionMarkPosition !== -1 ? questionMarkPosition : 0);
6161

62-
const parameters = hash.substr(questionMarkPosition + 1);
62+
const parameters = hash.slice(questionMarkPosition + 1);
6363
parameters.split('&').forEach((part) => {
6464
const [key, value] = part.split('=');
6565
context.parameters.set(key, decodeURIComponent(value));

‎js/app/service/veventService.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ app.service('VEventService', function(DavClient, StringUtility, XMLUtility, VEve
112112
const props = obj.propStat[0].properties;
113113
const calendarData = props[context.calendarDataPropName];
114114
const etag = props[context.eTagPropName];
115-
const uri = obj.href.substr(obj.href.lastIndexOf('/') + 1);
115+
const uri = obj.href.slice(obj.href.lastIndexOf('/') + 1);
116116

117117
try {
118118
const vevent = VEvent.fromRawICS(calendar, calendarData, uri, etag);

‎js/app/utility/colorUtility.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ app.service('ColorUtility', function() {
7676
var regex = new RegExp('^#([0-9a-f]{' + (colorString.length - 1) + '})$', 'i');
7777
matchedString = colorString.match(regex);
7878
return (Array.isArray(matchedString) && matchedString[1]) ? {
79-
r: parseInt(matchedString[1].substr(0, 2), 16),
80-
g: parseInt(matchedString[1].substr(2, 2), 16),
81-
b: parseInt(matchedString[1].substr(4, 2), 16)
79+
r: parseInt(matchedString[1].slice(0, 2), 16),
80+
g: parseInt(matchedString[1].slice(2, 4), 16),
81+
b: parseInt(matchedString[1].slice(4, 6), 16)
8282
} : fallbackColor;
8383

8484
default:

0 commit comments

Comments
 (0)