Wrap article encoding in try-catch

We wrap in a try-catch as decoding can sometimes fail if destination article does have special characters (e.g. %) in the title.
pull/716/head
Kevin Payravi 2024-06-11 07:12:42 -04:00
parent 3395aea9e9
commit 36b34ec55a
1 changed files with 8 additions and 2 deletions

View File

@ -199,8 +199,14 @@ function commonFunctionGetNewURL(originURL, matchingSite) {
destinationArticle = destinationArticle.replaceAll('_', ' ');
// Encode article
// We decode + encode to ensure we don't double-encode,
// in the event a string is already encoded
destinationArticle = encodeURIComponent(decodeURIComponent(destinationArticle));
// in the event a string is already encoded.
// We wrap in a try-catch as decoding can sometimes fail if destination article
// does have special characters (e.g. %) in the title.
try {
destinationArticle = encodeURIComponent(decodeURIComponent(destinationArticle));
} catch {
destinationArticle = encodeURIComponent(destinationArticle);
}
let searchParams = '';
switch (matchingSite['destination_platform']) {