mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
2350c3ae14
A place from the TREK index can carry its website the way Overture has it, such as fr.wikipedia.org/wiki/Chapelle_Sainte-Barbe_du_Faouët, and saving it to a collection or a trip failed with "website must be an http or https URL" over a field the dialog does not show (#2483). OpenStreetMap, Amap and booking mails hand over websites the same way. Every place a website comes in from outside now goes through one shared helper, normalizePlaceWebsite: the index client and its nearby search, the Overpass and OSM detail mappers, Google search and details, Amap, plugin search and the booking import. It completes a bare or protocol-relative host to https, keeps http and https as they are, and drops every other scheme and anything that is no address. Only the scheme is added, so an accented path is stored as written. placeWebsiteSchema completes a bare host the same way before its check, so an older client, a cached offline result, an MCP agent or a plugin is no longer refused, while javascript:, data: and mailto: still are. The REST controller, the plugin RPC and the enrichment now store the parsed value instead of the raw one, and create_place_accommodation takes the website through the same schema as create_place. safeHttpUrl still links only a value already stored in its final form, so nothing changes on screen. Tests: SHARED-WEBSITE-001 to 012, SHARED-PLACE-030 to 034, SHARED-COLLFILE-2483-01, COLLECTIONS-E2E-089 and 090, PLACES-E2E-2483-01 and 02, PLACES-CTRL-2483-01 (the louvre.fr case adjusted), MCP-PLACES-2483-01 to 03, MCP-ACCOM-2483-01, MCP-COLL-2483-01, PLACES-RPC-2483-01, MAPS-2483-01 to 05, MAPS-POIS-015, MAPS-GERS-010, AMAP-012b, TREK-PLACES-2483-01, PLUGIN-SEARCH-2483-01, BOOKING-IMPORT-2483-01, ENRICH-052e, ENRICH-102 extended, ENRICH-120 adjusted, FE-UTIL-SAFEURL-007.
59 lines
2.6 KiB
TypeScript
59 lines
2.6 KiB
TypeScript
import {
|
|
COLLECTION_GPX_PLACE_FIELDS,
|
|
MAX_COLLECTION_FILE_BYTES,
|
|
collectionFilePlaceSchema,
|
|
collectionGpxReadRequestSchema,
|
|
} from './collection-file.schema';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
describe('COLLECTION_GPX_PLACE_FIELDS (#2301)', () => {
|
|
// The type already refuses a missing key; this is the same promise at runtime,
|
|
// for a field that reaches the schema through a spread the type cannot see.
|
|
it('gives every field of a place in a list file a home in a GPX waypoint', () => {
|
|
const fields = Object.keys(COLLECTION_GPX_PLACE_FIELDS).sort();
|
|
expect(fields).toEqual(Object.keys(collectionFilePlaceSchema.shape).sort());
|
|
});
|
|
|
|
it('keeps what GPX has an element for out of the extension', () => {
|
|
const native = Object.entries(COLLECTION_GPX_PLACE_FIELDS)
|
|
.filter(([, home]) => home === 'waypoint')
|
|
.map(([field]) => field);
|
|
expect(native.sort()).toEqual(['category', 'description', 'lat', 'lng', 'name', 'notes', 'website']);
|
|
});
|
|
});
|
|
|
|
describe('collectionGpxReadRequestSchema (#2301)', () => {
|
|
const accepts = (body: unknown) => collectionGpxReadRequestSchema.safeParse(body).success;
|
|
|
|
it('takes the document as text, with the file name optional', () => {
|
|
expect(collectionGpxReadRequestSchema.parse({ gpx: '<gpx/>' })).toEqual({ gpx: '<gpx/>' });
|
|
const named = collectionGpxReadRequestSchema.parse({ gpx: '<gpx/>', file_name: 'favourites.gpx' });
|
|
expect(named.file_name).toBe('favourites.gpx');
|
|
});
|
|
|
|
it('refuses an empty document and one past the size a list file may have', () => {
|
|
expect(accepts({ gpx: '' })).toBe(false);
|
|
expect(accepts({ gpx: 'x'.repeat(MAX_COLLECTION_FILE_BYTES + 1) })).toBe(false);
|
|
});
|
|
|
|
it('refuses anything that is not text', () => {
|
|
expect(accepts({ gpx: { wpt: [] } })).toBe(false);
|
|
expect(accepts({})).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('collectionFilePlaceSchema website (#2483)', () => {
|
|
// The importer stores the parsed place, so the completed form is the one that
|
|
// lands; a link that is no page is still dropped rather than costing the place.
|
|
it('SHARED-COLLFILE-2483-01: a bare host arrives with https, a script link as null', () => {
|
|
const place = (website: unknown) => collectionFilePlaceSchema.parse({ name: 'Chapelle', website });
|
|
expect(place('fr.wikipedia.org/wiki/Chapelle_Sainte-Barbe_du_Faouët').website).toBe(
|
|
'https://fr.wikipedia.org/wiki/Chapelle_Sainte-Barbe_du_Faouët',
|
|
);
|
|
expect(place('https://example.fr').website).toBe('https://example.fr');
|
|
expect(place('javascript:alert(1)').website).toBeNull();
|
|
expect(place('Chapelle').website).toBeNull();
|
|
});
|
|
});
|