From 113026ce1304b463d9c3cb056b013ba9b1fdfef6 Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 13 May 2022 17:13:58 -0500 Subject: [PATCH] Fix:Sanitize new podcast folder names and ensure feedUrl is in feed metadata #589 --- client/components/modals/podcast/NewModal.vue | 2 +- client/plugins/init.client.js | 4 +++- server/controllers/PodcastController.js | 9 ++++++++- server/utils/fileUtils.js | 7 +++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/client/components/modals/podcast/NewModal.vue b/client/components/modals/podcast/NewModal.vue index 5d55783a..ec577ded 100644 --- a/client/components/modals/podcast/NewModal.vue +++ b/client/components/modals/podcast/NewModal.vue @@ -151,7 +151,7 @@ export default { this.fullPath = '' return } - this.fullPath = Path.join(this.selectedFolderPath, this.podcast.title) + this.fullPath = Path.join(this.selectedFolderPath, this.$sanitizeFilename(this.podcast.title)) }, submit() { const podcastPayload = { diff --git a/client/plugins/init.client.js b/client/plugins/init.client.js index c9c867eb..90dd7814 100644 --- a/client/plugins/init.client.js +++ b/client/plugins/init.client.js @@ -114,10 +114,11 @@ Vue.prototype.$calculateTextSize = (text, styles = {}) => { } } -Vue.prototype.$sanitizeFilename = (input, replacement = '') => { +Vue.prototype.$sanitizeFilename = (input, colonReplacement = ' - ') => { if (typeof input !== 'string') { return false } + var replacement = '' var illegalRe = /[\/\?<>\\:\*\|"]/g; var controlRe = /[\x00-\x1f\x80-\x9f]/g; var reservedRe = /^\.+$/; @@ -125,6 +126,7 @@ Vue.prototype.$sanitizeFilename = (input, replacement = '') => { var windowsTrailingRe = /[\. ]+$/; var sanitized = input + .replace(':', colonReplacement) // Replace first occurrence of a colon .replace(illegalRe, replacement) .replace(controlRe, replacement) .replace(reservedRe, replacement) diff --git a/server/controllers/PodcastController.js b/server/controllers/PodcastController.js index 4c54a262..c3de4e57 100644 --- a/server/controllers/PodcastController.js +++ b/server/controllers/PodcastController.js @@ -1,9 +1,10 @@ const axios = require('axios') const fs = require('fs-extra') +const Path = require('path') const Logger = require('../Logger') const { parsePodcastRssFeedXml } = require('../utils/podcastUtils') const LibraryItem = require('../objects/LibraryItem') -const { getFileTimestampsWithIno } = require('../utils/fileUtils') +const { getFileTimestampsWithIno, sanitizeFilename } = require('../utils/fileUtils') const filePerms = require('../utils/filePerms') class PodcastController { @@ -107,6 +108,12 @@ class PodcastController { if (!payload) { return res.status(500).send('Invalid podcast RSS feed') } + + if (!payload.podcast.metadata.feedUrl) { + // Not every RSS feed will put the feed url in their metadata + payload.podcast.metadata.feedUrl = url + } + res.json(payload) }).catch((error) => { console.error('Failed', error) diff --git a/server/utils/fileUtils.js b/server/utils/fileUtils.js index 3cf98f06..a0db36ee 100644 --- a/server/utils/fileUtils.js +++ b/server/utils/fileUtils.js @@ -176,17 +176,20 @@ module.exports.downloadFile = async (url, filepath) => { }) } -module.exports.sanitizeFilename = (filename, replacement = '') => { +module.exports.sanitizeFilename = (filename, colonReplacement = ' - ') => { if (typeof filename !== 'string') { return false } + + var replacement = '' var illegalRe = /[\/\?<>\\:\*\|"]/g; var controlRe = /[\x00-\x1f\x80-\x9f]/g; var reservedRe = /^\.+$/; var windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i; var windowsTrailingRe = /[\. ]+$/; - var sanitized = filename + sanitized = filename + .replace(':', colonReplacement) // Replace first occurrence of a colon .replace(illegalRe, replacement) .replace(controlRe, replacement) .replace(reservedRe, replacement)