diff --git a/server/utils/parsers/parsePodcastDescriptionForChapters.js b/server/utils/parsers/parsePodcastDescriptionForChapters.js index 3f1b4c75..8a83f149 100644 --- a/server/utils/parsers/parsePodcastDescriptionForChapters.js +++ b/server/utils/parsers/parsePodcastDescriptionForChapters.js @@ -1,3 +1,4 @@ +const sanitizeHtml = require('../../libs/sanitizeHtml') const Logger = require('../../Logger') /** @@ -27,13 +28,16 @@ module.exports.parse = (podcastDescription, audioDurationSecs) => { const timestampRegex = /\b(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?\b/ const chapterTitleRegex = /\b\d{1,2}:\d{1,2}(?::\d{1,2})?\b(?:\s+|\))(.+)$/ - const descriptionLineSplitRegex = /\<\s*\/\s*p\s*\>|\<\s*br\s*\s*\/\>|\n/ + + // Split on "

", "
", "\n", + const descriptionLineSplitRegex = /\<\s*\/\s*p\s*\>|\<\s*br\s*\/\>|\n|\<\s*\/\s*li\s*\>/ var descriptionLines = podcastDescription.split(descriptionLineSplitRegex) var newChapters = [] for (let i = 0; i < descriptionLines.length; i++) { - let line = descriptionLines[i] + // Strip all HTML tags out + let line = sanitizeHtml(descriptionLines[i], { allowedTags: [] }) let match = timestampRegex.exec(line) if (match == null) continue @@ -85,7 +89,7 @@ module.exports.parse = (podcastDescription, audioDurationSecs) => { newChapters[newChapters.length - 1].end = audioDurationSecs } - Logger.info(`[PodcastEpisode] Successfully generated ${newChapters.length} chapters`) + Logger.info(`Successfully generated ${newChapters.length} chapters`) if (newChapters.length == 1) { throw new Error('Only one chapter found, treating as invalid description') diff --git a/test/server/utils/parsers/parsePodcastDescriptionForChapters.test.js b/test/server/utils/parsers/parsePodcastDescriptionForChapters.test.js index 0fff4574..662c131d 100644 --- a/test/server/utils/parsers/parsePodcastDescriptionForChapters.test.js +++ b/test/server/utils/parsers/parsePodcastDescriptionForChapters.test.js @@ -1,5 +1,4 @@ const chai = require('chai') -const PodcastEpisode = require('../../../../server/models/PodcastEpisode') const expect = chai.expect const parsePodcastDescriptionForChapters = require('../../../../server/utils/parsers/parsePodcastDescriptionForChapters') @@ -69,6 +68,19 @@ describe('parsePodcastDescriptionForChapters', () => { { title: 'Chapter 7', id: 7, start: 2492, end: 2803 }, { title: 'Chapter 8', id: 8, start: 2803, end: 3060 } ] + }, + { + testName: 'Should handle html lists and chapters with html tags in the title', + description: '

Introduction



Chapters