mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
fix(client): give the desktop halves the same fixes their mobile twins got
Several of the fixes in this branch landed on a mobile screen while the desktop component with the identical bug sat in another package and was left alone, which leaves the two disagreeing about the same handler. So: the appearance tab flushes its debounced write on unmount, the journey share copy guards navigator.clipboard (undefined on a plain-HTTP self-hosted install), the admin collab toggle rolls back from a scoped snapshot instead of a stale one, the reservation modal parses metadata through the guarded helper rather than a bare JSON.parse that takes the route down, and the notification toggle surfaces its failures and stops racing concurrent toggles. The Journey components reached the memories provider-status endpoint with a raw fetch(), past every apiClient interceptor; they go through a small memoriesApi now. And the server half of the OSM menu_url finding: the client renders it through safeHttpUrl, so place-enrichment should not be handing a javascript: value out in the first place. The share section hides itself when the server says the link is not this user's to manage, rather than offering a create button that 403s.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { placeWebsiteSchema } from '@trek/shared';
|
||||
import type {
|
||||
MapsPlaceEnrichmentRequest,
|
||||
MapsPlaceEnrichmentResult,
|
||||
@@ -173,8 +174,11 @@ export function collectFacts(details: Record<string, unknown> | null): PlaceFact
|
||||
// OSM writes several cuisines semicolon-separated and underscored.
|
||||
if (cuisine) push('cuisine', cuisine.split(';').map((c) => c.replace(/_/g, ' ').trim()).filter(Boolean).join(', '));
|
||||
|
||||
const menu = typeof details.menu_url === 'string' ? details.menu_url : null;
|
||||
if (menu) push('menu', null, menu);
|
||||
// `menu_url` is a community-editable OSM tag that becomes an href on the
|
||||
// client, so it goes through the same allow-list as a place's website —
|
||||
// anything but http(s) is dropped rather than rendered as a link.
|
||||
const menu = typeof details.menu_url === 'string' ? details.menu_url.trim() : '';
|
||||
if (placeWebsiteSchema.safeParse(menu).success) push('menu', null, menu);
|
||||
|
||||
if (yesNo(details.outdoor_seating) === 'yes') push('outdoorSeating', null);
|
||||
if (yesNo(details.takeaway) === 'yes') push('takeaway', null);
|
||||
|
||||
@@ -729,6 +729,19 @@ describe('collectFacts', () => {
|
||||
expect(facts.find((f) => f.kind === 'internetAccess')).toEqual({ kind: 'internetAccess', value: null, url: null });
|
||||
});
|
||||
|
||||
it('ENRICH-052c: drops a menu_url that is not http(s)', () => {
|
||||
// Anyone can edit the OSM tag and the client turns it into an href.
|
||||
for (const menu_url of ['javascript:alert(1)', 'data:text/html,<script>1</script>', 'ftp://host/menu', '']) {
|
||||
expect(collectFacts(osm({ menu_url })).map((f) => f.kind)).toEqual([]);
|
||||
}
|
||||
});
|
||||
|
||||
it('ENRICH-052d: keeps an http menu_url and trims the surrounding whitespace', () => {
|
||||
expect(collectFacts(osm({ menu_url: ' http://example.org/menu ' }))).toEqual([
|
||||
{ kind: 'menu', value: null, url: 'http://example.org/menu' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('ENRICH-053: takes no chips at all from a Google place', () => {
|
||||
expect(collectFacts(null)).toEqual([]);
|
||||
// cuisine/outdoor_seating are OSM tagging and never appear on a Google blob;
|
||||
|
||||
Reference in New Issue
Block a user