:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(file-system): stop double escaping names when an object is updated (#113909)
Peter Kirkham405d9c773d9e
diff --git a/frontend/src/scenes/library/libraryUtils.test.ts b/frontend/src/scenes/library/libraryUtils.test.tsindex 5fb6270a0ca7..929a3744e907 100644--- a/frontend/src/scenes/library/libraryUtils.test.ts+++ b/frontend/src/scenes/library/libraryUtils.test.ts@@ -19,6 +19,8 @@ describe('libraryUtils', () => {test.each([['Unfiled/Insights/Checkout funnel', 'Checkout funnel'],['Unfiled/Insights/Signups a\\/b test', 'Signups a/b test'],+ ['Unfiled/Dashboards/go\\\\\\/revenue', 'go\\/revenue'],+ ['Unfiled/Folder\\\\/Revenue', 'Revenue'],['Top level', 'Top level'],])('names %s as %s', (path, name) => {expect(libraryObjectName({ path })).toBe(name)diff --git a/frontend/src/scenes/library/libraryUtils.ts b/frontend/src/scenes/library/libraryUtils.tsindex 92dd23a6fe4e..a957f0393285 100644--- a/frontend/src/scenes/library/libraryUtils.ts+++ b/frontend/src/scenes/library/libraryUtils.ts@@ -1,5 +1,6 @@import { routes } from 'scenes/scenes'+import { splitPath } from '~/layout/panel-layout/ProjectTree/utils'import { fileSystemTypes, getTreeItemsMetadata, getTreeItemsProducts } from '~/products'import { FileSystemEntry, FileSystemImport } from '~/queries/schema/schema-general'import { FileSystemType } from '~/types'@@ -122,8 +123,7 @@ export function libraryTypeForPath(path: string): string | null {/** The last segment of a file system path, with escaped slashes restored. */export function libraryObjectName(entry: Pick<FileSystemEntry, 'path'>): string {- const segments = entry.path.split(/(?<!\\)\//)- return (segments[segments.length - 1] || entry.path).replace(/\\\//g, '/')+ return splitPath(entry.path).pop() ?? entry.path}/** The type's name in lower case, for a label beside an object: "feature flag", but "SQL insight" keeps its acronym. */diff --git a/posthog/models/file_system/file_system.py b/posthog/models/file_system/file_system.pyindex 6a396697a4e0..995aed467114 100644--- a/posthog/models/file_system/file_system.py+++ b/posthog/models/file_system/file_system.py@@ -69,7 +69,7 @@ def create_or_update_file(for existing in all_existing:has_existing = Truesegments = split_path(existing.path)- segments[-1] = escape_path(name)+ segments[-1] = namenew_path = join_path(segments)existing.path = new_pathexisting.depth = len(segments)diff --git a/posthog/models/file_system/test/test_file_system.py b/posthog/models/file_system/test/test_file_system.pyindex a76ba1863c82..022ef801d254 100644--- a/posthog/models/file_system/test/test_file_system.py+++ b/posthog/models/file_system/test/test_file_system.py@@ -236,13 +236,13 @@ class TestFileSystemSurface(TestCase):)create_or_update_file(- team=self.team, base_folder="Old", name="New Name", file_type="insight", ref="7", href="", meta={}+ team=self.team, base_folder="Old", name="New/Name", file_type="insight", ref="7", href="", meta={})legacy.refresh_from_db()# The web write matched and renamed the legacy NULL row instead of creating a second one.self.assertEqual(FileSystem.objects.filter(type="insight", ref="7").count(), 1)- self.assertEqual(legacy.path, "Old/New Name")+ self.assertEqual(legacy.path, "Old/New\\/Name")def test_delete_file_is_scoped_to_surface(self):create_or_update_file(