From 9a34f1983bcc517df0755aff459a35f287e40acc Mon Sep 17 00:00:00 2001 From: jubnl Date: Sat, 11 Jul 2026 18:50:30 +0800 Subject: [PATCH] fix: update isGoogleMapsUrl to also detect Amap URLs - Add amap.com and uri.amap.com to URL detection - Keep legacy Google Maps URL patterns for backward compatibility - Update test expectations --- .../src/components/Planner/PlaceFormModal.helpers.test.ts | 6 ++++++ client/src/components/Planner/PlaceFormModal.helpers.ts | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client/src/components/Planner/PlaceFormModal.helpers.test.ts b/client/src/components/Planner/PlaceFormModal.helpers.test.ts index ad26cfd5..d1affd76 100644 --- a/client/src/components/Planner/PlaceFormModal.helpers.test.ts +++ b/client/src/components/Planner/PlaceFormModal.helpers.test.ts @@ -2,6 +2,12 @@ import { describe, it, expect } from 'vitest' import { isGoogleMapsUrl } from './PlaceFormModal.helpers' describe('isGoogleMapsUrl', () => { + it('accepts Amap URLs', () => { + expect(isGoogleMapsUrl('https://uri.amap.com/marker?position=1,2')).toBe(true) + expect(isGoogleMapsUrl('https://ditu.amap.com/search?query=test')).toBe(true) + expect(isGoogleMapsUrl('https://www.amap.com/dir')).toBe(true) + }) + it('accepts the short share hosts', () => { expect(isGoogleMapsUrl('https://maps.app.goo.gl/abc123')).toBe(true) expect(isGoogleMapsUrl('https://goo.gl/maps/xyz')).toBe(true) diff --git a/client/src/components/Planner/PlaceFormModal.helpers.ts b/client/src/components/Planner/PlaceFormModal.helpers.ts index 3a6b1b49..87ec318e 100644 --- a/client/src/components/Planner/PlaceFormModal.helpers.ts +++ b/client/src/components/Planner/PlaceFormModal.helpers.ts @@ -21,13 +21,13 @@ export function isGoogleMapsUrl(input: string): boolean { try { const { hostname, pathname } = new URL(input.trim()) const h = hostname.toLowerCase() - // maps.app.goo.gl, goo.gl/maps + // AMap / Gaode URLs + if (h === 'uri.amap.com') return true + if (h.endsWith('.amap.com')) return true + // Google Maps URL patterns (legacy) if (h === 'maps.app.goo.gl') return true if (h === 'goo.gl' && pathname.startsWith('/maps')) return true - // maps.google.* (e.g. maps.google.com, maps.google.co.uk) - // Must be maps.google. or maps.google.. — reject maps.google.evil.com if (/^maps\.google\.[a-z]{2,3}(\.[a-z]{2})?$/.test(h)) return true - // google.*/maps (e.g. google.com/maps, www.google.co.uk/maps) const bare = h.startsWith('www.') ? h.slice(4) : h if (/^google\.[a-z]{2,3}(\.[a-z]{2})?$/.test(bare) && pathname.startsWith('/maps')) return true return false