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

Nuxt Fatal Error. Error: Invalid character in string #266

Open
kovan opened this issue Sep 9, 2022 · 0 comments
Open

Nuxt Fatal Error. Error: Invalid character in string #266

kovan opened this issue Sep 9, 2022 · 0 comments

Comments

@kovan
Copy link

kovan commented Sep 9, 2022

Somehow the description of a <video> entry in the sitemap has weird characters which seem not to be in the range allowed by the XML specification.

Here is the stack trace:

at XMLStringifier.assertLegalChar (node_modules/xmlbuilder/lib/XMLStringifier.js:208:19)
at XMLStringifier.cdata (node_modules/xmlbuilder/lib/XMLStringifier.js:61:21)
at new XMLCData (node_modules/xmlbuilder/lib/XMLCData.js:21:35)
at XMLElement.cdata (node_modules/xmlbuilder/lib/XMLNode.js:318:17)
at SitemapItem.buildVideoElement (node_modules/sitemap/dist/lib/sitemap-item.js:79:47)
at Array.forEach ()
at SitemapItem.buildXML (node_modules/sitemap/dist/lib/sitemap-item.js:173:28)
at Sitemap.toString (node_modules/sitemap/dist/lib/sitemap.js:280:62)
at Sitemap.toXML (node_modules/sitemap/dist/lib/sitemap.js:147:21)
at generateSitemap (node_modules/@nuxtjs/sitemap/lib/generator.js:58:42)
at async generateSitemaps (node_modules/@nuxtjs/sitemap/lib/generator.js:32:5)
at async Promise.all (index 0)
at async node_modules/@nuxtjs/sitemap/lib/module.js:44:5
at async Nuxt.callHook (node_modules/hable/dist/hable.js:1:959)
at async Generator.generate (node_modules/@nuxt/generator/dist/generator.js:91:5)
at async generate$1 (node_modules/@nuxt/cli/dist/cli-generate.js:46:22)

Weirdly , the error always ends says the conflicting character is at the last position of the string, tested with different strings. So I don't know which character is causing problems.

I have tried removing conflicting characters (using this code), but the error persists.

And this is the code that generates the entry, which has been working fine for quite a long time until this issue appeared.
Nothing really special about it I think:

function videoToSitemapEntry(video) {
    // Reference:
    // https://developers.google.com/search/docs/advanced/sitemaps/video-sitemaps
    let json = {
        url: `/video/${video.videosdb.slug}`,
        video: [
            {
                thumbnail_loc: video.snippet.thumbnails.medium.url,
                title: video.snippet.title,
                description: video.snippet.description
                    ? removeXMLInvalidChars(video.snippet.description, true).substring(0, 2040)
                    : video.snippet.title,
                duration: video.videosdb.durationSeconds,
                publication_date: dateToISO(video.snippet.publishedAt)
            },
        ],
        priority: 1.0,
    }
    return json
}

Help appreciated.

Thank you for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant