Skip to content
Open
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
32 changes: 27 additions & 5 deletions frontend/web/app-assets/data/fullcalendar/php/get-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,40 @@
// Require our Event class and datetime utilities
require dirname(__FILE__) . '/utils.php';

function sendJsonError($message, $statusCode = 400) {
if (!headers_sent()) {
header('Content-Type: application/json');
header('HTTP/1.1 ' . $statusCode . ' Bad Request');
}
echo json_encode(array(
'error' => $message
));
exit;
}

// Short-circuit if the client did not give us a date range.
if (!isset($_GET['start']) || !isset($_GET['end'])) {
die("Please provide a date range.");
sendJsonError('Please provide a valid date range.');
}

// Parse the start/end parameters.
// These are assumed to be ISO8601 strings with no time nor timezone, like "2013-12-29".
// Since no timezone will be present, they will parsed as UTC.
$range_start = parseDateTime($_GET['start']);
$range_end = parseDateTime($_GET['end']);
try {
$range_start = parseDateTime($_GET['start']);
$range_end = parseDateTime($_GET['end']);
} catch (Exception $e) {
sendJsonError('Please provide a valid date range.');
}

// Parse the timezone parameter if it is present.
$timezone = null;
if (isset($_GET['timezone'])) {
$timezone = new DateTimeZone($_GET['timezone']);
try {
$timezone = new DateTimeZone($_GET['timezone']);
} catch (Exception $e) {
sendJsonError('Please provide a valid timezone.');
}
}

// Read and parse our events JSON file into an array of event data arrays.
Expand All @@ -47,4 +66,7 @@
}

// Send JSON to the client.
echo json_encode($output_arrays);
if (!headers_sent()) {
header('Content-Type: application/json');
}
echo json_encode($output_arrays);
17 changes: 17 additions & 0 deletions tests/check-fullcalendar-event-errors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail

target="frontend/web/app-assets/data/fullcalendar/php/get-events.php"

grep -q "function sendJsonError" "$target"
grep -q "Content-Type: application/json" "$target"
grep -q "Please provide a valid date range." "$target"
grep -q "Please provide a valid timezone." "$target"
grep -Fq 'catch (Exception $e)' "$target"

if grep -q "die(\"Please provide a date range.\")" "$target"; then
echo "fullcalendar event endpoint still hard-stops with plain text" >&2
exit 1
fi

echo "FullCalendar event error guard passed."