Decode HTML entities in Audible title and subtitle

Audible/audnex metadata can contain HTML entities such as `"` and
`&` that were passed through untouched, so titles like
`The "Hitler" Myth` were displayed literally instead of
`The "Hitler" Myth`.

Decode the entities at the ingestion boundary in `cleanResult` using the
existing `htmlSanitizer.stripAllTags` helper (the same plain-text
treatment already used for collection/playlist names). This decodes once,
avoiding the double-decoding of legitimate literal entities.

Fixes #5340

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
TowyTowy 2026-07-09 00:12:18 +02:00
parent 6f03467f35
commit 98e1e5a29a
2 changed files with 23 additions and 2 deletions

View file

@ -1,6 +1,7 @@
const axios = require('axios').default
const Logger = require('../Logger')
const { isValidASIN } = require('../utils/index')
const htmlSanitizer = require('../utils/htmlSanitizer')
class Audible {
#responseTimeout = 10000
@ -66,8 +67,10 @@ class Audible {
}
return {
title,
subtitle: subtitle || null,
// Audible metadata can contain HTML entities (e.g. `&quot;`, `&amp;`) that are otherwise
// shown literally in titles/subtitles. Decode them at the ingestion boundary. See #5340
title: title ? htmlSanitizer.stripAllTags(title) : title,
subtitle: subtitle ? htmlSanitizer.stripAllTags(subtitle) : null,
author: authors ? authors.map(({ name }) => name).join(', ') : null,
narrator: narrators ? narrators.map(({ name }) => name).join(', ') : null,
publisher: publisherName,

View file

@ -45,4 +45,22 @@ describe('Audible', () => {
expect(result).to.equal('.5')
})
})
describe('cleanResult', () => {
it('should decode HTML entities in the title and subtitle (#5340)', () => {
const result = audible.cleanResult({
title: 'The &quot;Hitler&quot; Myth',
subtitle: 'Image &amp; Reality in the Third Reich',
asin: 'B0TESTASIN'
})
expect(result.title).to.equal('The "Hitler" Myth')
expect(result.subtitle).to.equal('Image & Reality in the Third Reich')
})
it('should keep a null subtitle when none is provided', () => {
const result = audible.cleanResult({ title: 'A Plain Title', asin: 'B0TESTASIN' })
expect(result.title).to.equal('A Plain Title')
expect(result.subtitle).to.equal(null)
})
})
})