Skip to content

Commit

Permalink
Merge pull request #1572 from effigies/enh/empty-dataset-name
Browse files Browse the repository at this point in the history
ENH: Check for empty or whitespace-only dataset names
  • Loading branch information
effigies authored Dec 16, 2022
2 parents d3d4439 + af2dba3 commit 40206be
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
6 changes: 6 additions & 0 deletions bids-validator/utils/issues/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,12 @@ export default {
reason:
'This dataset contains remote files. If you would like to validate with remote files, use the --remoteFiles option.',
},
115: {
key: 'EMPTY_DATASET_NAME',
severity: 'warning',
reason:
'The Name field of dataset_description.json is present but empty of visible characters.',
},
123: {
key: 'INVALID JSON ENCODING',
severity: 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,55 @@ import { assert } from 'chai'
import checkDatasetDescription from '../checkDatasetDescription'

describe('checkDatasetDescription', () => {
describe('checkAuthorField', () => {
it('returns no issues with valid Authors field', () => {
describe('checkNameAndAuthorsFields', () => {
it('returns no issues with valid Name and Authors field', () => {
const validJsonContentsDict = {
'/dataset_description.json': {
Name: 'Electric Boots',
Authors: ['Benny', 'the Jets'],
},
}
const issues = checkDatasetDescription(validJsonContentsDict)
assert.lengthOf(issues, 0)
})
})
describe('checkNameField', () => {
it('returns code 115 when Name is empty', () => {
const invalidJsonContentsDict = {
'/dataset_description.json': {
Name: '',
},
}
const issues = checkDatasetDescription(invalidJsonContentsDict)
assert(
issues.findIndex((issue) => issue.code === 115) > -1,
'issues include a code 115',
)
})
it('returns code 115 when name only contains whitespace', () => {
const invalidJsonContentsDict = {
'/dataset_description.json': {
Name: ' \t\r\n\f\v\u2003',
},
}
const issues = checkDatasetDescription(invalidJsonContentsDict)
assert(
issues.findIndex((issue) => issue.code === 115) > -1,
'issues include a code 115',
)
})
it('returns no issues with one non-whitespace character', () => {
const validJsonContentsDict = {
'/dataset_description.json': {
Name: ' \u2708 ',
Authors: ['Benny', 'the Jets'],
},
}
const issues = checkDatasetDescription(validJsonContentsDict)
assert.lengthOf(issues, 0)
})
})
describe('checkAuthorField', () => {
it('returns code 102 when there is only one author present', () => {
const invalidJsonContentsDict = {
'/dataset_description.json': {
Expand Down
15 changes: 14 additions & 1 deletion bids-validator/validators/bids/checkDatasetDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const checkDatasetDescription = (jsonContentsDict) => {
} else {
const datasetDescription = jsonContentsDict['/dataset_description.json']

// check to ensure that the dataset description Authors are
// check to ensure that the dataset description fields are
// properly formatted
issues = issues.concat(checkNameField(datasetDescription.Name))
issues = issues.concat(checkAuthorField(datasetDescription.Authors))

// if genetic info json present ensure mandatory GeneticDataset present
Expand All @@ -33,6 +34,18 @@ const checkDatasetDescription = (jsonContentsDict) => {
return issues
}

const checkNameField = (name) => {
const issues = []
// missing name will be caught by validation (later)
if (name !== undefined) {
const nonws = /\S/
if (!name.match(nonws)) {
issues.push(new Issue({ code: 115 }))
}
}
return issues
}

const checkAuthorField = (authors) => {
const issues = []
// because this test happens before schema validation,
Expand Down

0 comments on commit 40206be

Please sign in to comment.