A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix(tables): stop URL linkification at delimiters, not whitespace (#10570)
Abdul Rehmaneb9960fe7782
diff --git a/frontend/src/utils/__tests__/url-parser.test.ts b/frontend/src/utils/__tests__/url-parser.test.tsindex 2d3b8456b2..ce0f818b35 100644--- a/frontend/src/utils/__tests__/url-parser.test.ts+++ b/frontend/src/utils/__tests__/url-parser.test.ts@@ -98,4 +98,30 @@ describe("parseContent", () => {{ type: "url", url: "https://github.com" },]);});++ it("stops at JSON delimiters instead of swallowing them (#10567)", () => {+ const parts = parseContent(+ '[{"name":"inv.pdf","url":"https://example.com/p/AAA"}]',+ );+ expect(parts).toEqual([+ { type: "text", value: '[{"name":"inv.pdf","url":"' },+ { type: "url", url: "https://example.com/p/AAA" },+ { type: "text", value: '"}]' },+ ]);+ });++ it("does not include a trailing double-quote in the href", () => {+ const parts = parseContent('"https://example.com/x"');+ expect(parts).toContainEqual({+ type: "url",+ url: "https://example.com/x",+ });+ });++ it("keeps apostrophes, which are valid in URLs", () => {+ const parts = parseContent("https://example.com/O'Reilly");+ expect(parts).toEqual([+ { type: "url", url: "https://example.com/O'Reilly" },+ ]);+ });});diff --git a/frontend/src/utils/json/__tests__/json-parser.test.ts b/frontend/src/utils/json/__tests__/json-parser.test.tsnew file mode 100644index 0000000000..10949bc0aa--- /dev/null+++ b/frontend/src/utils/json/__tests__/json-parser.test.ts@@ -0,0 +1,33 @@+/* Copyright 2026 Marimo. All rights reserved. */+import { describe, expect, it } from "vitest";+import { jsonToMarkdown } from "../json-parser";++describe("jsonToMarkdown URL linkification", () => {+ it("links a plain URL", () => {+ const md = jsonToMarkdown([{ link: "https://marimo.io/path" }]);+ expect(md).toContain("[https://marimo.io/path](https://marimo.io/path)");+ });++ it("stops the link at the JSON delimiter, not the trailing quote (#10567)", () => {+ const md = jsonToMarkdown([+ { attachments: '[{"url":"https://example.com/p/AAA"}]' },+ ]);+ // The link target ends exactly at the URL; the closing `"}]` is left as+ // text rather than pulled into the href.+ expect(md).toContain("(https://example.com/p/AAA)");+ expect(md).not.toContain('https://example.com/p/AAA"');+ });++ it("does not swallow a trailing double-quote into the link", () => {+ const md = jsonToMarkdown([{ v: '"https://example.com/x"' }]);+ expect(md).toContain("(https://example.com/x)");+ expect(md).not.toContain('https://example.com/x"');+ });++ it("leaves existing markdown links untouched", () => {+ const md = jsonToMarkdown([{ v: "[docs](https://marimo.io/docs)" }]);+ expect(md).toContain("[docs](https://marimo.io/docs)");+ // Must not double-wrap into [[docs](url)](url).+ expect(md).not.toContain("[[docs]");+ });+});diff --git a/frontend/src/utils/json/json-parser.ts b/frontend/src/utils/json/json-parser.tsindex 0fcd17ed62..7df9d15475 100644--- a/frontend/src/utils/json/json-parser.ts+++ b/frontend/src/utils/json/json-parser.ts@@ -1,7 +1,10 @@/* Copyright 2026 Marimo. All rights reserved. */+import { URL_REGEX } from "../url-parser";import type { JsonString } from "./base64";+const GLOBAL_URL_REGEX = new RegExp(URL_REGEX.source, "g");+declare global {interface BigInt {toJSON(): unknown;@@ -126,9 +129,8 @@ function formatValueForMarkdown(value: unknown): string {return placeholder;});- // Convert plain URLs to markdown links- const urlRegex = /(https?:\/\/\S+)/g;- stringValue = stringValue.replaceAll(urlRegex, "[$1]($1)");+ // Convert plain URLs to markdown links using the shared URL matcher.+ stringValue = stringValue.replaceAll(GLOBAL_URL_REGEX, "[$1]($1)");// Restore markdown links from placeholdersfor (const [placeholder, original] of placeholders) {diff --git a/frontend/src/utils/url-parser.ts b/frontend/src/utils/url-parser.tsindex 8bffad8ecf..7b33721903 100644--- a/frontend/src/utils/url-parser.ts+++ b/frontend/src/utils/url-parser.ts@@ -1,6 +1,7 @@/* Copyright 2026 Marimo. All rights reserved. */-const urlRegex = /(https?:\/\/\S+)/;+/** Matches HTTP(S) URLs without consuming surrounding delimiters. */+export const URL_REGEX = /(https?:\/\/[^\s"<>`{}|\\^]+)/;const imageRegex = /\.(png|jpe?g|gif|webp|svg|ico)(\?.*)?$/i;const dataImageRegex = /^data:image\//i;const knownImageDomains = ["avatars.githubusercontent.com"];@@ -19,9 +20,9 @@ export function parseContent(text: string): ContentPart[] {return [{ type: "image", url: text }];}- const parts = text.split(urlRegex).filter((part) => part !== "");+ const parts = text.split(URL_REGEX).filter((part) => part !== "");return parts.map((part) => {- const isUrl = urlRegex.test(part);+ const isUrl = URL_REGEX.test(part);if (isUrl) {const isImage =imageRegex.test(part) ||