Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(shared): EPUB preview titles keep emoji whole at the name limit #48273

Opensaphid(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/48273/headopened View on GitHub

Showing 2 changed files with 17 additions and 1 deletion.

x
0 of 2 viewed, 2 left
11 additions and 0 deletionspackages/shared/src/filePreview.test.tsModified
View file
@@ -26,6 +26,17 @@
expect(epubPreviewRequest(viewer)).toBeNull();
});
​
+ it("does not split an emoji at the EPUB preview name limit", () => {
+ const prefix = "a".repeat(299);
+ const source = "https://code.example/api/assets/book.epub";
+ const split = new URL(epubPreviewUrl(source, `${prefix}📚.epub`)!);
+ const fits = new URL(epubPreviewUrl(source, `${prefix.slice(1)}📚.epub`)!);
+​
+ expect(epubPreviewRequest(split)?.name.isWellFormed()).toBe(true);
+ expect(epubPreviewRequest(split)?.name).toBe(prefix);
+ expect(epubPreviewRequest(fits)?.name).toBe(`${prefix.slice(1)}📚`);
+ });
+​
it.each([
["zip", "archive", "application/zip"],
["jar", "archive", "application/java-archive"],
6 additions and 1 deletionpackages/shared/src/filePreview.tsModified
View file
@@ -21,7 +21,12 @@
if (!path?.startsWith("/api/assets/")) return null;
const asset = parseUrl(path, url.origin);
if (asset?.origin !== url.origin || !asset.pathname.startsWith("/api/assets/")) return null;
- return { src: asset.href, name: params.get("name")?.slice(0, 300) || "EPUB" };
+ const name = params.get("name")?.slice(0, 300) ?? "";
+ const last = name.charCodeAt(name.length - 1);
+ return {