Skip to content

Commit

Permalink
fix: crlf was not working correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
richtera committed Feb 20, 2024
1 parent 321b786 commit c7a02cc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/getDataFromExternalSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export const getDataFromExternalSources = (
// - check whether those could represent valid JSON data.
// - then validate the data as JSON
// - then verfiy the data against the verification method

// Improved JSON detection. We now check the first and up to the last 3 bytes.
// The 3 bytes can be `]` or '}' with either SPACE, LF or CRLF at the end.
const capture: number[] = [];
capture.push(receivedData[0]);
if (receivedData.length > 3) {
Expand All @@ -121,7 +124,7 @@ export const getDataFromExternalSources = (
// Check if the beginning or end are
// { and } => JSON.stringify({...}) => pretty much 100% of our JSON will be this.
// [ and ] => JSON.stringify([...])
if (/^(\[.*\]|\{.*\})\s?$/.test(key)) {
if (/^(\[.*\]|\{.*\})\s*$/.test(key)) {
const json = Buffer.from(receivedData).toString();
const value = JSON.parse(json);
if (isDataAuthentic(value, urlDataWithHash.verification)) {
Expand Down

0 comments on commit c7a02cc

Please sign in to comment.