Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions data/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ below is also machine-enforced by [`places.schema.json`](places.schema.json), wh
- `type`: must match the filename exactly
- `lat`/`lng`: from Google Maps (right-click pin, "What's here?"). Any real-world coordinate works: `places.schema.json` checks latitude is between -90 and 90 and longitude between -180 and 180.
- `address`: optional, short, human-readable
- `website`, `phone` and `hours`: all optional, so a record without them stays valid. `website` is the place's own `https://` page. `phone` is international format with no spaces or punctuation, like `+442074127000` (drop the national `0` in `+44 (0)20...`). `hours` is short free text of at most 120 characters, like `Mon-Fri 09:00-17:00`. They must come from the place's own website or listing, not a third-party directory, and you note where and when you checked them in the PR (see [Verification](#verification)).
- `exam` and `valid_till` (exam centres only): `exam` is one label per exam, so the same exam is never spelled two ways. Use `IELTS`, `TOEFL`, `Goethe-Zertifikat (A1-C2)`, `DELF/DALF` (`TEF/TCF/DELF/DALF` for a centre that also takes the TEF and TCF), `DELF`, `DELE`, `TOMER Turkish Proficiency Certificate` or `SAT`, and add a new label here when you add a new exam. `valid_till` is the date to reconfirm the centre by: 6 months after you last checked it (the PR date for a new record).
- `gmaps_link`: Google Maps share link (Share -> Copy link)
- Do not add rating, review count, or verified date to the JSON. Those go in the PR.
Expand Down Expand Up @@ -71,6 +72,21 @@ re-checked the place:
- `npm run validate` fails on a malformed `verified` block (missing or empty
`by`, a non-date or impossible `on`, or extra keys).

### Phone, website and opening hours

Opening hours and phone numbers go stale faster than a pin. When a PR adds or
changes `website`, `phone` or `hours`:

- take each one from the place's **own** website or listing, never from a
directory or a map app's aggregated "popular times";
- put the page you read it from and the date you checked it in the PR
description (it stays in the PR, not in the JSON, like the other proof);
- leave a field out rather than guess: all three are optional;
- when you re-verify a place (above), re-check these three as well.

`npm run validate` checks the format only (`https://` URL, `+` and digits for
the phone, short single-line hours). It cannot tell you the value is right.

## Quality gate (must pass before merge)

Include in your pull request description:
Expand Down
17 changes: 17 additions & 0 deletions data/places.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@
"type": "string",
"description": "Optional, short, human-readable"
},
"website": {
"type": "string",
"pattern": "^https://[^\\s]+$",
"maxLength": 300,
"description": "Optional. The place's own https:// website or listing page. Must come from the place itself, not a third-party directory."
},
"phone": {
"type": "string",
"pattern": "^\\+[1-9][0-9]{6,14}$",
"description": "Optional. International format with no spaces, e.g. \"+442074127000\" (E.164). Must come from the place's own site or listing."
},
"hours": {
"type": "string",
"minLength": 1,
"maxLength": 120,
"description": "Optional. Short free text for now, e.g. \"Mon-Fri 09:00-17:00\". Must come from the place's own site or listing."
},
"gmaps_link": {
"type": "string",
"pattern": "^https://(maps\\.google\\.com(\\?|/)|maps\\.app\\.goo\\.gl/|www\\.google\\.com/maps/|goo\\.gl/maps/)"
Expand Down
15 changes: 15 additions & 0 deletions data/places/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@
"lat": 51.5299119,
"lng": -0.1276918,
"address": "96 Euston Road, London NW1 2DB",
"website": "https://www.bl.uk/visit",
"hours": "Mon-Thu 09:30-20:00, Fri 09:30-18:00, Sat 09:30-17:00, Sun 11:00-17:00",
"gmaps_link": "https://maps.google.com/?q=51.5299119,-0.1276918",
"added_by": "yakew7",
"verified": {
Expand Down Expand Up @@ -996,6 +998,8 @@
"lat": -35.2965236,
"lng": 149.1295736,
"address": "Parkes Place, Parkes, Canberra ACT 2600, Australia",
"website": "https://www.library.gov.au/visit",
"phone": "+61262621111",
"gmaps_link": "https://maps.google.com/?q=-35.2965236,149.1295736",
"added_by": "yakew7",
"verified": {
Expand Down Expand Up @@ -1360,6 +1364,9 @@
"lat": -33.8672,
"lng": 151.214,
"address": "Macquarie St, Sydney NSW 2000, Australia",
"website": "https://www.sl.nsw.gov.au/visit-us/opening-hours",
"phone": "+61292731414",
"hours": "Mon-Thu 09:00-20:00, Fri 09:00-17:00, Sat-Sun 10:00-17:00",
"gmaps_link": "https://maps.google.com/?q=-33.8672,151.2140",
"added_by": "yakew7"
},
Expand Down Expand Up @@ -5752,6 +5759,9 @@
"lat": -37.8097696,
"lng": 144.9655352,
"address": "328 Swanston St, Melbourne VIC 3000, Australia",
"website": "https://www.slv.vic.gov.au/visit",
"phone": "+61386647000",
"hours": "Daily 10:00-18:00",
"gmaps_link": "https://maps.google.com/?q=-37.8097696,144.9655352",
"added_by": "anaydhawan"
},
Expand Down Expand Up @@ -5824,6 +5834,9 @@
"lat": 38.888674,
"lng": -77.004636,
"address": "10 First Street SE, Washington, DC 20540",
"website": "https://www.loc.gov/visit/",
"phone": "+12027079779",
"hours": "Tue-Wed 10:00-17:00, Thu 10:00-20:00, Fri-Sat 10:00-17:00, closed Sun-Mon",
"gmaps_link": "https://maps.google.com/?q=38.888674,-77.004636",
"added_by": "propcgamer20-png",
"verified": {
Expand All @@ -5840,6 +5853,8 @@
"lat": 53.341125,
"lng": -6.2545,
"address": "7-8 Kildare Street, Dublin D02 P638",
"website": "https://www.nli.ie/contact",
"phone": "+35316030200",
"gmaps_link": "https://maps.google.com/?q=53.341125,-6.2545",
"added_by": "propcgamer20-png",
"verified": {
Expand Down
18 changes: 18 additions & 0 deletions scripts/lib/data-validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ export function isHttpUrl(value) {
}
}

/**
* True when `value` is an international phone number in E.164 form: "+", a non-zero
* country digit, then 6 to 14 more digits, with no spaces or punctuation (#356).
*/
export function isE164Phone(value) {
return typeof value === "string" && /^\+[1-9][0-9]{6,14}$/.test(value);
}

/** True when `value` is a short, non-blank, single-line opening-hours text (#356). */
export function isOpeningHours(value) {
return (
typeof value === "string" &&
value.trim().length > 0 &&
value.length <= 120 &&
!/[\r\n]/.test(value)
);
}

/** True when `value` is a string containing an em dash. House rule, see #193/#194. */
export function hasEmDash(value) {
return typeof value === "string" && value.includes("—");
Expand Down
53 changes: 51 additions & 2 deletions scripts/lib/place-submission.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* and synchronous; network and file access live in the callers.
*/

import { normalizePlaceName } from "./data-validation.mjs";
import { isE164Phone, isHttpsUrl, normalizePlaceName } from "./data-validation.mjs";

export const SUBMISSION_LABEL = "place-submission";
export const SUBMISSION_MARKER = "<!-- studymap-place-submission:v1 -->";
Expand All @@ -24,7 +24,7 @@ export const PLACE_TYPES = [
"gov_offices",
];

const MAX = { name: 120, city: 60, contributor: 60, note: 500 };
const MAX = { name: 120, city: 60, contributor: 60, note: 500, website: 300, hours: 120 };

// Same host rules as the place schema's gmaps_link pattern, plus the short
// links the "Share" button produces (which the processing script resolves).
Expand Down Expand Up @@ -57,6 +57,18 @@ function clean(value, max) {
.slice(0, max);
}

/**
* "+44 (20) 7412-7000" and "0044 20 7412 7000" both become "+442074127000".
* Anything that is still not E.164 afterwards is left for the caller to reject.
*/
export function normalizePhone(input) {
// "(0)" is the national trunk digit written after the country code ("+44 (0)20 ..."); it is not dialled from abroad.
const stripped = String(input ?? "")
.replace(/\(0\)/g, "")
.replace(/[\s().-]/g, "");
return stripped.startsWith("00") ? `+${stripped.slice(2)}` : stripped;
}

/**
* Validates and normalises a raw submission. Returns
* { ok: true, value } or { ok: false, error }.
Expand All @@ -78,13 +90,44 @@ export function normalizeSubmission(raw) {
return { ok: false, error: "Enter a valid Google Maps link." };
}

// Optional contact details (#356). Blank means "not given"; a value that is
// given but malformed is rejected, so a typo never silently disappears.
// The form sends the real field as `placeWebsite`: `website` on the request is the
// hidden honeypot, which the route drops when filled, so the two must not share a
// key. A stored submission (read back from an issue) uses the normalised `website`.
const websiteInput = [raw.placeWebsite, raw.website].find(
(value) => typeof value === "string" && value.trim() !== "",
);
const website = typeof websiteInput === "string" ? websiteInput.trim() : "";
if (
website &&
(website.length > MAX.website || !isHttpsUrl(website) || /\s/.test(website))
) {
return {
ok: false,
error: "Enter the website as an https:// link, or leave it blank.",
};
}
const phone = normalizePhone(typeof raw.phone === "string" ? raw.phone : "");
if (phone && !isE164Phone(phone)) {
return {
ok: false,
error:
"Enter the phone with its country code, like +442074127000, or leave it blank.",
};
}
const hours = clean(raw.hours, MAX.hours);

return {
ok: true,
value: {
name,
type,
city,
gmapsLink,
...(website ? { website } : {}),
...(phone ? { phone } : {}),
...(hours ? { hours } : {}),
contributor: clean(raw.contributor, MAX.contributor),
note: clean(raw.note, MAX.note),
},
Expand All @@ -99,6 +142,9 @@ export function buildIssueBody(sub) {
`**Type:** ${sub.type}`,
`**City:** ${sub.city}`,
`**Google Maps link:** ${sub.gmapsLink}`,
...(sub.website ? [`**Website:** ${sub.website}`] : []),
...(sub.phone ? [`**Phone:** ${sub.phone}`] : []),
...(sub.hours ? [`**Hours:** ${sub.hours}`] : []),
`**Contributor:** ${sub.contributor || "(anonymous)"}`,
...(sub.note ? [`**Note:** ${sub.note}`] : []),
"",
Expand Down Expand Up @@ -211,6 +257,9 @@ export function buildPlaceRecord({ sub, coords, country, id }) {
country,
lat: coords.lat,
lng: coords.lng,
...(sub.website ? { website: sub.website } : {}),
...(sub.phone ? { phone: sub.phone } : {}),
...(sub.hours ? { hours: sub.hours } : {}),
gmaps_link: `https://maps.google.com/?q=${coords.lat},${coords.lng}`,
added_by: addedByFor(sub.contributor),
};
Expand Down
6 changes: 5 additions & 1 deletion scripts/process-place-submission.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ export async function processSubmission({ body, records, resolve = resolveShortL
const record = buildPlaceRecord({ sub, coords, country, id });
return {
status: "ready",
message: `Added \`${id}\`. Check the pin location and the quality gate (rating 4.0+, 50+ reviews) before merging.`,
message: `Added \`${id}\`. Check the pin location and the quality gate (rating 4.0+, 50+ reviews) before merging.${
record.website || record.phone || record.hours
? " The website, phone and hours were typed by the submitter: confirm each against the place's own site or listing, and drop any you cannot."
: ""
}`,
record,
sub,
};
Expand Down
26 changes: 26 additions & 0 deletions scripts/validate-places.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* - lat/lng are numbers within the schema's min/max bounds
* - gmaps_link matches the schema's pattern
* - valid_till is a real ISO date (YYYY-MM-DD), when present
* - website is an https:// URL, phone is E.164 (+ then 7 to 15 digits, no
* spaces) and hours is short single-line text, when present (all three
* are optional, so no existing record needs them)
* - No em dashes in any string field
* - gmaps_link in the ?q=<lat>,<lng> form points at the record's own lat/lng
* (within 0.01 degrees)
Expand All @@ -37,7 +40,10 @@ import {
gmapsLinkCoordinates,
hasEmDash,
isCountryCode,
isE164Phone,
isHttpsUrl,
isLatLngPlaceholderGmapsLink,
isOpeningHours,
isRealIsoDate,
} from "./lib/data-validation.mjs";

Expand Down Expand Up @@ -198,6 +204,26 @@ for (const file of files) {
err(loc, `valid_till must be a real ISO date (YYYY-MM-DD), got "${r.valid_till}"`);
}

// Optional contact details (#356): format only, the fields stay optional
if (r.website !== undefined && (!isHttpsUrl(r.website) || r.website.length > 300)) {
err(
loc,
`website must be an https:// URL of at most 300 characters, got ${JSON.stringify(r.website)}`,
);
}
if (r.phone !== undefined && !isE164Phone(r.phone)) {
err(
loc,
`phone must be in international format with no spaces, like "+442074127000", got ${JSON.stringify(r.phone)}`,
);
}
if (r.hours !== undefined && !isOpeningHours(r.hours)) {
err(
loc,
`hours must be short single-line text of at most 120 characters, like "Mon-Fri 09:00-17:00", got ${JSON.stringify(r.hours)}`,
);
}

// lat bounds
if (r.lat !== undefined) {
if (typeof r.lat !== "number") {
Expand Down
26 changes: 26 additions & 0 deletions src/app/api/submit-place/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,32 @@ describe("POST /api/submit-place", () => {
expect(createIssue).not.toHaveBeenCalled();
});

it("files a real website sent as placeWebsite, which is not the honeypot (#356)", async () => {
const res = await post({
...good,
placeWebsite: "https://www.bl.uk/",
phone: "+44 20 7412 7000",
hours: "Mon-Fri 09:30-20:00",
website: "",
});
expect(res.status).toBe(201);
expect(createIssue).toHaveBeenCalledWith(
"test-token",
expect.objectContaining({
website: "https://www.bl.uk/",
phone: "+442074127000",
hours: "Mon-Fri 09:30-20:00",
}),
);
});

it("rejects a malformed phone with a message instead of dropping it (#356)", async () => {
const res = await post({ ...good, phone: "020 7412 7000" });
expect(res.status).toBe(400);
expect(await res.json()).toMatchObject({ ok: false, reason: "invalid" });
expect(createIssue).not.toHaveBeenCalled();
});

it("returns 503 unavailable when no token is configured", async () => {
delete process.env.PLACE_SUBMISSION_TOKEN;
const res = await post(good);
Expand Down
3 changes: 3 additions & 0 deletions src/app/docs/(article)/places-api/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const RESPONSE_EXAMPLE = `{
"lat": 18.9674,
"lng": 72.8339,
"address": "Fort, Mumbai 400001",
"website": "https://example.org/library",
"phone": "+912222660000",
"hours": "Mon-Sat 10:00-18:00",
"gmaps_link": "https://maps.google.com/?q=18.9674,72.8339",
"added_by": "thunderblitzyt-eng"
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/map/place-detail-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { humanizeCity, PLACE_TYPE_LABELS } from "@/lib/types";
import { CategoryIcon } from "@/components/map/category-icon";
import { PlacePhotoGallery } from "@/components/map/place-photo-gallery";
import { SharePlaceCard } from "@/components/map/share-place-card";
import { PlaceContact } from "@/components/pins/place-contact";
import { VerifiedBadge } from "@/components/pins/verified-badge";
import { Button } from "@/components/ui/button";
import {
Expand Down Expand Up @@ -56,6 +57,8 @@ export function PlaceDetailDrawer({ place, open, onOpenChange }: PlaceDetailDraw
</div>
)}

<PlaceContact place={place} variant="detailed" />

{place.exam && (
<div className="space-y-1">
<p className="text-xs font-medium text-muted-foreground">Exam centre</p>
Expand Down
Loading
Loading