Skip to content

Commit d3e9f4d

Browse files
fix(tlon): keep fragment image URLs as media blocks
1 parent ba080f9 commit d3e9f4d

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

extensions/tlon/src/urbit/send.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { afterEach, describe, expect, it, vi } from "vitest";
2+
import { buildMediaStory } from "./send.js";
3+
import { createImageBlock } from "./story.js";
24

35
vi.mock("@urbit/aura", () => ({
46
scot: vi.fn(() => "mocked-ud"),
@@ -7,6 +9,30 @@ vi.mock("@urbit/aura", () => ({
79
},
810
}));
911

12+
describe("buildMediaStory", () => {
13+
it("treats image URLs with fragments as image blocks", () => {
14+
expect(buildMediaStory("caption", "https://cdn.example/image.png#preview")).toEqual([
15+
{ inline: ["caption"] },
16+
createImageBlock("https://cdn.example/image.png#preview", ""),
17+
]);
18+
});
19+
20+
it("keeps non-image fragment URLs as links", () => {
21+
expect(buildMediaStory(undefined, "https://cdn.example/page#preview")).toEqual([
22+
{
23+
inline: [
24+
{
25+
link: {
26+
href: "https://cdn.example/page#preview",
27+
content: "https://cdn.example/page#preview",
28+
},
29+
},
30+
],
31+
},
32+
]);
33+
});
34+
});
35+
1036
describe("sendDm", () => {
1137
afterEach(() => {
1238
vi.restoreAllMocks();

extensions/tlon/src/urbit/story.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export function createImageBlock(
180180
* Check if URL looks like an image
181181
*/
182182
export function isImageUrl(url: string): boolean {
183-
const imageExtensions = /\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)(\?.*)?$/i;
183+
const imageExtensions = /\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)(?:\?.*)?(?:#.*)?$/i;
184184
return imageExtensions.test(url);
185185
}
186186

0 commit comments

Comments
 (0)