diff --git a/autotests/structureddata/eventbrite-broken-json.html b/autotests/structureddata/eventbrite-broken-json.html new file mode 100644 index 0000000000000000000000000000000000000000..993c9e2f0bc433eee41fa29cd5261ec3c02012c9 --- /dev/null +++ b/autotests/structureddata/eventbrite-broken-json.html @@ -0,0 +1,16 @@ + + + diff --git a/autotests/structureddata/eventbrite-broken-json.json b/autotests/structureddata/eventbrite-broken-json.json new file mode 100644 index 0000000000000000000000000000000000000000..bbe78cc553ce17821108568ba4cadfd803697e3a --- /dev/null +++ b/autotests/structureddata/eventbrite-broken-json.json @@ -0,0 +1,14 @@ +[ + { + "@context": "http://schema.org", + "@type": "EventReservation", + "reservationFor": { + "@type": "Event", + "endDate": "2020-12-12T17:00:00+01:00", + "name": "XMAS Open Mobility Data Community Remote Meetup 2020 #xomdcrm20", + "startDate": "2020-12-11T17:00:00+01:00" + }, + "reservationNumber": "XXX007", + "reservationStatus": "http://schema.org/Confirmed" + } +] diff --git a/src/generic/structureddataextractor.cpp b/src/generic/structureddataextractor.cpp index fbd70d0174f3f13a5941dbf105ffe874ab720e32..40b75cf4d556a0d15e3756f4c88356ad47d49540 100644 --- a/src/generic/structureddataextractor.cpp +++ b/src/generic/structureddataextractor.cpp @@ -37,6 +37,18 @@ static QByteArray fixupJson(const QByteArray &data) output.append("]"); } + // Eventbrite adds commas where there shouldn't be one... + for (int idx = output.indexOf("\",\n"); idx > 0 && idx + 3 < output.size(); idx = output.indexOf("\",\n", idx)) { + const auto comma = idx + 1; + idx += 3; + while (idx < output.size() && std::isspace(output[idx])) { + ++idx; + } + if (idx < output.size() && output[idx] == '}') { + output[comma] = ' '; + } + } + return output; }