From 3913dfffb9be129f2122ba18db2ecf02150da66f Mon Sep 17 00:00:00 2001 From: Rojikku Date: Wed, 13 May 2026 15:03:26 -0400 Subject: [PATCH] fix(content-manager) parseChubUrl should clean URL before relying on length (#5604) Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com> --- src/endpoints/content-manager.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/endpoints/content-manager.js b/src/endpoints/content-manager.js index f034a35fb..76ce9ef84 100644 --- a/src/endpoints/content-manager.js +++ b/src/endpoints/content-manager.js @@ -556,11 +556,6 @@ async function downloadPygmalionCharacter(id) { */ function parseChubUrl(str) { const splitStr = str.split('/'); - const length = splitStr.length; - - if (length < 2) { - return null; - } let domainIndex = -1; @@ -570,20 +565,25 @@ function parseChubUrl(str) { } }); - const lastTwo = domainIndex !== -1 ? splitStr.slice(domainIndex + 1) : splitStr; + const cleanUrl = domainIndex !== -1 ? splitStr.slice(domainIndex + 1) : splitStr; + const length = cleanUrl.length; - const firstPart = lastTwo[0].toLowerCase(); + if (length < 2) { + return null; + } + + const firstPart = cleanUrl[0].toLowerCase(); if (firstPart === 'characters' || firstPart === 'lorebooks') { const type = firstPart === 'characters' ? 'character' : 'lorebook'; - const id = type === 'character' ? lastTwo.slice(1).join('/') : lastTwo.join('/'); + const id = type === 'character' ? cleanUrl.slice(1).join('/') : cleanUrl.join('/'); return { id: id, type: type, }; } else if (length === 2) { return { - id: lastTwo.join('/'), + id: cleanUrl.join('/'), type: 'character', }; }