Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated String.prototype.substr() #31699

Closed
wants to merge 5 commits into from
Closed
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
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ module.exports = {
// allows custom xxxx:xxx events formats
ignores: ['/^[a-z]+(?:-[a-z]+)*:[a-z]+(?:-[a-z]+)*$/u'],
}],
'no-restricted-syntax': [
'warn',
'WithStatement',
{
'message': 'substr() is deprecated, use slice() or substring() instead',
'selector': "MemberExpression > Identifier[name='substr']"
}
],
},
settings: {
jsdoc: {
Expand Down
2 changes: 1 addition & 1 deletion apps/federatedfilesharing/js/external.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
var remote = share.remote;
var owner = share.ownerDisplayName || share.owner;
var name = share.name;
var remoteClean = (remote.substr(0, 8) === 'https://') ? remote.substr(8) : remote.substr(7);
var remoteClean = (remote.slice(0, 8) === 'https://') ? remote.slice(8) : remote.slice(7);

if (!passwordProtected) {
OC.dialogs.confirm(
Expand Down
6 changes: 3 additions & 3 deletions apps/files/js/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ OC.FileUpload.prototype = {
var dotPos = name.lastIndexOf('.');
var extPart = '';
if (dotPos > 0) {
this._newName = name.substr(0, dotPos);
extPart = name.substr(dotPos);
this._newName = name.slice(0, dotPos);
extPart = name.slice(dotPos);
} else {
this._newName = name;
}
Expand Down Expand Up @@ -562,7 +562,7 @@ OC.Uploader.prototype = _.extend({

// remove trailing slash
if (fullPath.charAt(fullPath.length - 1) === '/') {
fullPath = fullPath.substr(0, fullPath.length - 1);
fullPath = fullPath.slice(0, -1);
}

var self = this;
Expand Down
4 changes: 2 additions & 2 deletions apps/files/js/fileactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
}
}
if (mime) {
var mimePart = mime.substr(0, mime.indexOf('/'));
var mimePart = mime.substring(0, mime.indexOf('/'));
if (this.actions[mimePart]) {
actions = $.extend(actions, this.actions[mimePart]);
}
Expand Down Expand Up @@ -302,7 +302,7 @@
getDefaultFileAction: function(mime, type, permissions) {
var mimePart;
if (mime) {
mimePart = mime.substr(0, mime.indexOf('/'));
mimePart = mime.substring(0, mime.indexOf('/'));
}
var name = false;
if (mime && this.defaults[mime]) {
Expand Down
2 changes: 1 addition & 1 deletion apps/files/js/fileinfomodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
if (!this.has('mimetype')) {
return false;
}
return this.get('mimetype').substr(0, 6) === 'image/'
return this.get('mimetype').slice(0, 6) === 'image/'
|| this.get('mimetype') === 'application/postscript'
|| this.get('mimetype') === 'application/illustrator'
|| this.get('mimetype') === 'application/x-photoshop';
Expand Down
20 changes: 10 additions & 10 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -1291,11 +1291,11 @@
}
var targetPath = $(event.target).data('dir');
var dir = this.getCurrentDirectory();
while (dir.substr(0,1) === '/') {//remove extra leading /'s
dir = dir.substr(1);
while (dir.slice(0, 1) === '/') {//remove extra leading /'s
dir = dir.slice(1);
}
dir = '/' + dir;
if (dir.substr(-1,1) !== '/') {
if (dir.slice(-1) !== '/') {
dir = dir + '/';
}
// do nothing if dragged on current dir
Expand Down Expand Up @@ -1724,8 +1724,8 @@
extension = name;
// split extension from filename for non dirs
} else if (mime !== 'httpd/unix-directory' && name.indexOf('.') !== -1) {
basename = name.substr(0, name.lastIndexOf('.'));
extension = name.substr(name.lastIndexOf('.'));
basename = name.slice(0, name.lastIndexOf('.'));
extension = name.slice(name.lastIndexOf('.'));
} else {
basename = name;
extension = false;
Expand All @@ -1742,7 +1742,7 @@
var $firstConflict = $(conflictingItems[0]),
firstConflictPath = $firstConflict.attr('data-path') + '/';
if (firstConflictPath.charAt(0) === '/') {
firstConflictPath = firstConflictPath.substr(1);
firstConflictPath = firstConflictPath.slice(1);
}
if (firstConflictPath && firstConflictPath !== '/') {
$firstConflict.find('td.filename span.innernametext').prepend($('<span></span>').addClass('conflict-path').text(firstConflictPath));
Expand All @@ -1751,7 +1751,7 @@

var conflictPath = path + '/';
if (conflictPath.charAt(0) === '/') {
conflictPath = conflictPath.substr(1);
conflictPath = conflictPath.slice(1);
}
if (path && path !== '/') {
nameSpan.append($('<span></span>').addClass('conflict-path').text(conflictPath));
Expand All @@ -1765,7 +1765,7 @@
}
if (fileData.extraData) {
if (fileData.extraData.charAt(0) === '/') {
fileData.extraData = fileData.extraData.substr(1);
fileData.extraData = fileData.extraData.slice(1);
}
nameSpan.addClass('extra-data').attr('title', fileData.extraData);
}
Expand Down Expand Up @@ -2696,7 +2696,7 @@
if ((dir + fileName) === targetPathAndName) {
var dotIndex = targetPathAndName.indexOf(".");
if ( dotIndex > 1) {
var leftPartOfName = targetPathAndName.substr(0, dotIndex);
var leftPartOfName = targetPathAndName.slice(0, dotIndex);
var fileNumber = leftPartOfName.match(/\d+/);
// TRANSLATORS name that is appended to copied files with the same name, will be put in parenthesis and appended with a number if it is the second+ copy
var copyNameLocalized = t('files', 'copy');
Expand Down Expand Up @@ -2928,7 +2928,7 @@
tr.attr('data-file', newName);
var basename = newName;
if (newName.indexOf('.') > 0 && tr.data('type') !== 'dir') {
basename = newName.substr(0, newName.lastIndexOf('.'));
basename = newName.slice(0, newName.lastIndexOf('.'));
}
td.find('a.name span.nametext').text(basename);
td.children('a.name').children(':not(.thumbnail-wrapper)').show();
Expand Down
4 changes: 2 additions & 2 deletions apps/files/js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
* Fix path name by removing double slash at the beginning, if any
*/
fixPath: function(fileName) {
if (fileName.substr(0, 2) == '//') {
return fileName.substr(1);
if (fileName.slice(0, 2) == '//') {
return fileName.slice(1);
}
return fileName;
},
Expand Down
2 changes: 1 addition & 1 deletion apps/files/js/tagsplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
applyFileTags: function (fileName, tagNames, $favoriteMarkEl, isFavorite) {
var encodedPath = OC.encodePath(fileName);
while (encodedPath[0] === '/') {
encodedPath = encodedPath.substr(1);
encodedPath = encodedPath.slice(1);
}
return $.ajax({
url: OC.generateUrl('/apps/files/api/v1/files/') + encodedPath,
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/components/VirtualList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default Vue.extend({
}

// Get and consume reusable key or generate a new one
const key = unusedKeys.pop() || Math.random().toString(36).substr(2)
const key = unusedKeys.pop() || Math.random().toString(36).slice(2)
this.$_recycledPool[key] = item[this.dataKey]
return { key, item }
})
Expand Down
6 changes: 3 additions & 3 deletions apps/files_external/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getSelectedApplicable($row) {
// FIXME: don't rely on string parts to detect groups...
var pos = (value.indexOf)?value.indexOf('(group)'): -1;
if (pos !== -1) {
groups.push(value.substr(0, pos));
groups.push(value.slice(0, pos));
} else {
users.push(value);
}
Expand Down Expand Up @@ -986,7 +986,7 @@ MountConfigListView.prototype = _.extend({
Object.values(result).forEach(function(storageParams) {
var storageConfig;
var isUserGlobal = storageParams.type === 'system' && self._isPersonal;
storageParams.mountPoint = storageParams.mountPoint.substr(1); // trim leading slash
storageParams.mountPoint = storageParams.mountPoint.slice(1); // trim leading slash
if (isUserGlobal) {
storageConfig = new UserGlobalStorageConfig();
} else {
Expand Down Expand Up @@ -1041,7 +1041,7 @@ MountConfigListView.prototype = _.extend({
var onCompletion = jQuery.Deferred();
var $rows = $();
result.forEach(function(storageParams) {
storageParams.mountPoint = (storageParams.mountPoint === '/')? '/' : storageParams.mountPoint.substr(1); // trim leading slash
storageParams.mountPoint = (storageParams.mountPoint === '/')? '/' : storageParams.mountPoint.slice(1); // trim leading slash
var storageConfig = new self._storageConfigClass();
_.extend(storageConfig, storageParams);
var $tr = self.newStorage(storageConfig, onCompletion, true);
Expand Down
12 changes: 6 additions & 6 deletions apps/files_sharing/js/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ OCA.Sharing.PublicApp = {

if (typeof FileActions !== 'undefined') {
// Show file preview if previewer is available, images are already handled by the template
if (mimetype.substr(0, mimetype.indexOf('/')) !== 'image' && $('.publicpreview').length === 0) {
if (mimetype.substring(0, mimetype.indexOf('/')) !== 'image' && $('.publicpreview').length === 0) {
// Trigger default action if not download TODO
var spec = FileActions.getDefaultFileAction(mimetype, 'file', OC.PERMISSION_READ);
if (spec && spec.action) {
Expand Down Expand Up @@ -160,7 +160,7 @@ OCA.Sharing.PublicApp = {
&& (mimetype.startsWith('image/') || mimetype.startsWith('video/') || mimetype.startsWith('audio'))) {
OCA.Viewer.setRootElement('#imgframe')
OCA.Viewer.open({ path: '/' })
} else if (mimetype.substr(0, mimetype.indexOf('/')) === 'text' && window.btoa) {
} else if (mimetype.substring(0, mimetype.indexOf('/')) === 'text' && window.btoa) {
if (OC.appswebroots['files_texteditor'] !== undefined ||
OC.appswebroots['text'] !== undefined) {
// the text editor handles the previewing
Expand All @@ -177,12 +177,12 @@ OCA.Sharing.PublicApp = {
}).then(function (data) {
self._showTextPreview(data, previewHeight);
});
} else if ((previewSupported === 'true' && mimetype.substr(0, mimetype.indexOf('/')) !== 'video') ||
mimetype.substr(0, mimetype.indexOf('/')) === 'image' &&
} else if ((previewSupported === 'true' && mimetype.substring(0, mimetype.indexOf('/')) !== 'video') ||
mimetype.substring(0, mimetype.indexOf('/')) === 'image' &&
mimetype !== 'image/svg+xml') {
img.attr('src', OC.generateUrl('/apps/files_sharing/publicpreview/' + token + '?' + OC.buildQueryString(params)));
imgcontainer.appendTo('#imgframe');
} else if (mimetype.substr(0, mimetype.indexOf('/')) !== 'video') {
} else if (mimetype.substring(0, mimetype.indexOf('/')) !== 'video') {
img.attr('src', mimetypeIcon);
img.attr('width', 128);
// "#imgframe" is either empty or it contains an audio preview that
Expand Down Expand Up @@ -417,7 +417,7 @@ OCA.Sharing.PublicApp = {
var self = this;
var location = window.location.protocol + '//' + window.location.host + OC.getRootPath();

if(remote.substr(-1) !== '/') {
if(remote.slice(-1) !== '/') {
remote += '/'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default {
},
dropdownId() {
// Generate a unique ID for ARIA attributes
return `dropdown-${Math.random().toString(36).substr(2, 9)}`
return `dropdown-${Math.random().toString(36).slice(2, 11)}`
},
},
watch: {
Expand Down
2 changes: 1 addition & 1 deletion core/src/OC/backbone-webdav.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function parsePropFindResult(result, davProperties) {
function parseIdFromLocation(url) {
var queryPos = url.indexOf('?')
if (queryPos > 0) {
url = url.substr(0, queryPos)
url = url.slice(0, queryPos)
}

var parts = url.split('/')
Expand Down
6 changes: 3 additions & 3 deletions core/src/OC/query-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Parses a URL query string into a JS map
*
* @param {string} queryString query string in the format param1=1234&param2=abcde&param3=xyz
* @return {Object<string, string>} map containing key/values matching the URL parameters

Check warning on line 31 in core/src/OC/query-string.js

View workflow job for this annotation

GitHub Actions / NPM lint

Use object shorthand or index signatures instead of `Object`, e.g., `{[key: string]: string}`
*/
export const parse = queryString => {
let pos
Expand All @@ -40,7 +40,7 @@
}
pos = queryString.indexOf('?')
if (pos >= 0) {
queryString = queryString.substr(pos + 1)
queryString = queryString.slice(pos + 1)
}
const parts = queryString.replace(/\+/g, '%20').split('&')
for (let i = 0; i < parts.length; i++) {
Expand All @@ -49,8 +49,8 @@
pos = part.indexOf('=')
if (pos >= 0) {
components = [
part.substr(0, pos),
part.substr(pos + 1),
part.slice(0, pos),
part.slice(pos + 1),
]
} else {
// key only
Expand All @@ -77,7 +77,7 @@
/**
* Builds a URL query from a JS map.
*
* @param {Object<string, string>} params map containing key/values matching the URL parameters

Check warning on line 80 in core/src/OC/query-string.js

View workflow job for this annotation

GitHub Actions / NPM lint

Use object shorthand or index signatures instead of `Object`, e.g., `{[key: string]: string}`
* @return {string} String containing a URL query (without question) mark
*/
export const build = params => {
Expand Down
4 changes: 2 additions & 2 deletions core/src/OC/util-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* or a map
* @param {string} [url] URL to be used, otherwise the current URL will be used,
* using the params as query string
* @param {boolean} [replace=false] whether to replace instead of pushing

Check warning on line 48 in core/src/OC/util-history.js

View workflow job for this annotation

GitHub Actions / NPM lint

Defaults are not permitted on @param
*/
_pushState(params, url, replace) {
let strParams
Expand Down Expand Up @@ -133,11 +133,11 @@
const hash = window.location.hash
const pos = hash.indexOf('?')
if (pos >= 0) {
return hash.substr(pos + 1)
return hash.slice(pos + 1)
}
if (hash.length) {
// remove hash sign
return hash.substr(1)
return hash.slice(1)
}
return ''
},
Expand Down
4 changes: 2 additions & 2 deletions core/src/OC/webroot.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ if (typeof webroot === 'undefined') {
webroot = location.pathname
const pos = webroot.indexOf('/index.php/')
if (pos !== -1) {
webroot = webroot.substr(0, pos)
webroot = webroot.slice(0, pos)
} else {
webroot = webroot.substr(0, webroot.lastIndexOf('/'))
webroot = webroot.substring(0, webroot.lastIndexOf('/'))
}
}

Expand Down
16 changes: 8 additions & 8 deletions core/src/files/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import escapeHTML from 'escape-html'
var Client = function(options) {
this._root = options.root
if (this._root.charAt(this._root.length - 1) === '/') {
this._root = this._root.substr(0, this._root.length - 1)
this._root = this._root.slice(0, -1)
}

let url = Client.PROTOCOL_HTTP + '://'
Expand Down Expand Up @@ -225,10 +225,10 @@ import escapeHTML from 'escape-html'
_buildUrl: function() {
let path = this._buildPath.apply(this, arguments)
if (path.charAt([path.length - 1]) === '/') {
path = path.substr(0, path.length - 1)
path = path.slice(0, -1)
}
if (path.charAt(0) === '/') {
path = path.substr(1)
path = path.slice(1)
}
return this._baseUrl + '/' + path
},
Expand Down Expand Up @@ -269,8 +269,8 @@ import escapeHTML from 'escape-html'
continue
}

const headerName = headerRows[i].substr(0, sepPos)
const headerValue = headerRows[i].substr(sepPos + 2)
const headerName = headerRows[i].slice(0, sepPos)
const headerValue = headerRows[i].slice(sepPos + 2)

if (!headers[headerName]) {
// make it an array
Expand Down Expand Up @@ -305,12 +305,12 @@ import escapeHTML from 'escape-html'
*/
_parseFileInfo: function(response) {
let path = decodeURIComponent(response.href)
if (path.substr(0, this._root.length) === this._root) {
path = path.substr(this._root.length)
if (path.slice(0, this._root.length) === this._root) {
path = path.slice(this._root.length)
}

if (path.charAt(path.length - 1) === '/') {
path = path.substr(0, path.length - 1)
path = path.slice(0, -1)
}

if (response.propStat.length === 0 || response.propStat[0].status !== 'HTTP/1.1 200 OK') {
Expand Down
2 changes: 1 addition & 1 deletion core/src/systemtags/systemtagscollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(function(OC) {

function filterFunction(model, term) {
return model.get('name').substr(0, term.length).toLowerCase() === term.toLowerCase()
return model.get('name').slice(0, term.length).toLowerCase() === term.toLowerCase()
}

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/2250-2250.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/4107-4107.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/614-614.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/6318-6318.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions dist/6654-6654.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/6654-6654.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion dist/7608-7608.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/7816-7816.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/8494-8494.js

Large diffs are not rendered by default.

File renamed without changes.
1 change: 1 addition & 0 deletions dist/8494-8494.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/comments-comments-app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/comments-comments-app.js.map

Large diffs are not rendered by default.

Loading
Loading