Skip to content

Commit

Permalink
Pull Request honestbleeps#5478: Fix: download images from posts with …
Browse files Browse the repository at this point in the history
…emoji-only, extra long, exotic emoji containing titles
  • Loading branch information
uwx committed Nov 8, 2023
2 parents 6a952ad + 9cf96e3 commit a211a50
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/modules/showImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1333,11 +1333,13 @@ export class Media {
const ext = re.exec(downloadUrl);
const thing = Thing.from(wrapper);
let title = thing && thing.getTitle();
title = title.replace(/[*|?:"~<>\\\/]|(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/gi, '');
title = title.replace(/\p{Emoji}|\p{Emoji_Component}/ug, '');
title = title.slice(0, 120); // titles may be longer than the filesystem allows
title = title.trim();
if (title && ext) {
let extension = ext[1];
if (extension.includes('?')) extension = extension.split('?')[0];
title = title.replace(/[*|?:"~<>\\\/]|(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/gi, '');
title = title.trim();
const filename = `${title}.${extension}`;
download(downloadUrl, filename);
} else download(downloadUrl);
Expand Down

0 comments on commit a211a50

Please sign in to comment.