diff --git a/src/bids/types/dataset.js b/src/bids/types/dataset.js index a648dc14..f095d738 100644 --- a/src/bids/types/dataset.js +++ b/src/bids/types/dataset.js @@ -9,6 +9,9 @@ import { generateIssue, IssueError } from '../../issues/issues' import { getMergedSidecarData, organizedPathsGenerator, parseRelativePath } from '../../utils/paths' import { BidsHedIssue } from './issues' +/** Matches a "HED" key in raw JSON text, allowing whitespace before the colon. */ +const HED_KEY_PATTERN = /"HED"\s*:/ + /** * A BIDS dataset. * @@ -202,7 +205,7 @@ export class BidsDataset { ) return sidecarIssues } - if (!jsonText.includes('"HED":')) { + if (!HED_KEY_PATTERN.test(jsonText)) { return sidecarIssues } try { diff --git a/tests/otherTests/dataset.spec.js b/tests/otherTests/dataset.spec.js index 41cb2789..48f05db3 100644 --- a/tests/otherTests/dataset.spec.js +++ b/tests/otherTests/dataset.spec.js @@ -154,6 +154,24 @@ describe('BidsDataset', () => { getFileContentSpy.mockRestore() }) + + it.each([ + ['a space', '{ "trial_type": { "HED" : { "go": "Sensory-event" } } }'], + ['a line break', '{ "trial_type": { "HED"\n: { "go": "Sensory-event" } } }'], + ])('should load a sidecar with %s before the colon after "HED"', async (_, jsonText) => { + class SpacedHedAccessor extends BidsFileAccessor { + async getFileContent() { + return jsonText + } + } + const accessor = new SpacedHedAccessor('/fake/dir', new Map([['task-testing_events.json', {}]])) + const dataset = new BidsDataset(accessor) + const issues = await dataset.setSidecars() + + expect(issues.length).toBe(0) + expect(dataset.sidecarMap.has('task-testing_events.json')).toBe(true) + expect(dataset.sidecarMap.get('task-testing_events.json').sidecarKeys.has('trial_type')).toBe(true) + }) }) describe('validate', () => {