Skip to content

Commit

Permalink
Merge pull request #45387 from nextcloud/fix/xml2js
Browse files Browse the repository at this point in the history
fix(files): Drop `xml2js` dependency and use browser native DOMParser
  • Loading branch information
susnux authored May 17, 2024
2 parents 7bc4ccb + ecb149e commit 495d397
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 60 deletions.
32 changes: 16 additions & 16 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@ import type { Upload } from '@nextcloud/upload'
import type { UserConfig } from '../types.ts'
import type { View, ContentsWithRoot } from '@nextcloud/files'
import { getCapabilities } from '@nextcloud/capabilities'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { Folder, Node, Permission } from '@nextcloud/files'
import { getCapabilities } from '@nextcloud/capabilities'
import { translate as t } from '@nextcloud/l10n'
import { join, dirname } from 'path'
import { orderBy } from 'natural-orderby'
import { Parser } from 'xml2js'
import { showError } from '@nextcloud/dialogs'
import { translate, translatePlural } from '@nextcloud/l10n'
import { Type } from '@nextcloud/sharing'
import { UploadPicker } from '@nextcloud/upload'
import { loadState } from '@nextcloud/initial-state'
Expand Down Expand Up @@ -469,6 +468,8 @@ export default defineComponent({
},
methods: {
t,
async fetchContent() {
this.loading = true
const dir = this.dir
Expand Down Expand Up @@ -569,17 +570,19 @@ export default defineComponent({
}
// Else we try to parse the response error message
try {
const parser = new Parser({ trim: true, explicitRoot: false })
const response = await parser.parseStringPromise(upload.response?.data)
const message = response['s:message'][0] as string
if (typeof message === 'string' && message.trim() !== '') {
// The server message is also translated
showError(this.t('files', 'Error during upload: {message}', { message }))
return
if (typeof upload.response?.data === 'string') {
try {
const parser = new DOMParser()
const doc = parser.parseFromString(upload.response.data, 'text/xml')
const message = doc.getElementsByTagName('s:message')[0]?.textContent ?? ''
if (message.trim() !== '') {
// The server message is also translated
showError(t('files', 'Error during upload: {message}', { message }))
return
}
} catch (error) {
logger.error('Could not parse message', { error })
}
} catch (error) {
logger.error('Error while parsing', { error })
}
// Finally, check the status code if we have one
Expand Down Expand Up @@ -632,9 +635,6 @@ export default defineComponent({
toggleGridView() {
this.userConfigStore.update('grid_view', !this.userConfig.grid_view)
},
t: translate,
n: translatePlural,
},
})
</script>
Expand Down
6 changes: 3 additions & 3 deletions dist/7883-7883.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/core-common.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/core-unsupported-browser-redirect.js

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

2 changes: 1 addition & 1 deletion dist/core-unsupported-browser-redirect.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/core-unsupported-browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-unsupported-browser.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/files-main.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions dist/files-main.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
* @license MIT
*/

/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */

/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */

/**
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
Expand Down
2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/files-sidebar.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

15 changes: 1 addition & 14 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@
"vuedraggable": "^2.24.3",
"vuex": "^3.6.2",
"vuex-router-sync": "^5.0.0",
"webdav": "^5.5.0",
"xml2js": "^0.6.2"
"webdav": "^5.5.0"
},
"devDependencies": {
"@babel/node": "^7.22.10",
Expand Down

0 comments on commit 495d397

Please sign in to comment.