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

refactor: replace deprecated String.prototype.substr() #6718

Merged
merged 1 commit into from
Apr 12, 2022
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
7 changes: 7 additions & 0 deletions changelog/unreleased/enhancement-replace-deprecated-substr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Replace deprecated String.prototype.substr()

We've replaced all occurrences of the deprecated String.prototype.substr()
function with String.prototype.slice() which works similarly but isn't
deprecated.

https://github.com/owncloud/web/pull/6718
2 changes: 1 addition & 1 deletion packages/web-app-files/src/mixins/actions/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default {
this.hideModal()

if (sameResource) {
const newPath = resource.path.substr(1, resource.path.lastIndexOf('/'))
const newPath = resource.path.slice(1, resource.path.lastIndexOf('/') + 1)
this.$router.push({
params: {
item: '/' + newPath + newName || '/'
Expand Down
3 changes: 2 additions & 1 deletion packages/web-app-files/src/mixins/deleteResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ export default {
isSameResource(this.resourcesToDelete[0], this.currentFolder)
) {
const resourcePath = this.resourcesToDelete[0].path
parentFolderPath = resourcePath.substr(0, resourcePath.lastIndexOf('/'))
const lastSlash = resourcePath.lastIndexOf('/')
parentFolderPath = resourcePath.slice(0, lastSlash !== -1 ? lastSlash : 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would've handled the lastSlash being -1 outside of slice, but it works as expected, so I'm fine with it. 😉

}

if (parentFolderPath !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-files/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default {
},
renameFile(context, { file, newValue, client, publicPage, isSameResource }) {
if (file !== undefined && newValue !== undefined && newValue !== file.name) {
const newPath = file.webDavPath.substr(1, file.webDavPath.lastIndexOf('/'))
const newPath = file.webDavPath.slice(1, file.webDavPath.lastIndexOf('/') + 1)
if (publicPage) {
return client.publicFiles
.move(file.webDavPath, newPath + newValue, context.getters.publicLinkPassword)
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-preview/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default {
y: this.thumbDimensions,
// strip double quotes from etag
// we have no etag, e.g. on shared with others page
c: this.activeFilteredFile.etag?.substr(1, this.activeFilteredFile.etag.length - 2),
c: this.activeFilteredFile.etag?.slice(1, -1),
scalingup: 0,
preview: 1,
a: 1
Expand Down
4 changes: 2 additions & 2 deletions packages/web-runtime/src/components/Topbar/Notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default {
this.$client.requests
.ocs({
service: 'apps/' + app,
action: link.substr(link.lastIndexOf('api')),
action: link.slice(link.lastIndexOf('api')),
method: type
})
.then((res) => {
Expand All @@ -86,7 +86,7 @@ export default {
})
res.json().then((json) => {
json.ocs.data.forEach((item) => {
const path = item.path.substr(0, item.path.lastIndexOf('/') + 1)
const path = item.path.slice(0, item.path.lastIndexOf('/') + 1)
const absolutePath = this.$route.params.item ? this.$route.params.item : '/'
if (path === absolutePath) this.reloadFilesList(path)
})
Expand Down
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ const plugins = [
}
files[c].forEach((f) => {
const fp = path.parse(f.fileName)
const lastDash = fp.name.lastIndexOf('-')
acc[c][
production ? fp.name.substr(0, fp.name.lastIndexOf('-')) || fp.name : fp.name
production ? fp.name.slice(0, lastDash !== -1 ? lastDash : 0) || fp.name : fp.name
] = c === 'js' ? fp.name : f.fileName
})

Expand Down