From 7e2a8ccc544972fda50e1e19b6e5b98b3e781b44 Mon Sep 17 00:00:00 2001 From: Alexander Jones Date: Fri, 10 Jun 2022 14:14:33 -0500 Subject: [PATCH] Make double quote an invalid character Also add minor documentation and code quality changes. --- validator/stringParser.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/validator/stringParser.js b/validator/stringParser.js index d2dc65b2..185eda89 100644 --- a/validator/stringParser.js +++ b/validator/stringParser.js @@ -9,18 +9,17 @@ const closingGroupCharacter = ')' const delimiters = new Set([',']) /** - * Split a full HED string into tags. + * Split a HED string into tags. * - * @param {string} hedString The full HED string. + * @param {string} hedString The HED string to be split. * @param {Schemas} hedSchemas The collection of HED schemas. - * @param {int} groupStartingIndex The start index of the group in the full HED string. - * @returns {[ParsedHedTag[], object]} An array of HED tags (top-level relative to the passed string) and any issues found. + * @param {int} groupStartingIndex The start index of the containing group in the full HED string. + * @returns {[ParsedHedTag[], Object]} An array of HED tags (top-level relative to the passed string) and any issues found. */ const splitHedString = function (hedString, hedSchemas, groupStartingIndex = 0) { - const doubleQuoteCharacter = '"' const colonCharacter = ':' const slashCharacter = '/' - const invalidCharacters = ['{', '}', '[', ']', '~'] + const invalidCharacters = ['{', '}', '[', ']', '~', '"'] const hedTags = [] const conversionIssues = [] @@ -79,10 +78,7 @@ const splitHedString = function (hedString, hedSchemas, groupStartingIndex = 0) resetStartingIndex = false } const character = hedString.charAt(i) - if (character === doubleQuoteCharacter) { - // Skip double quotes - continue - } else if (character === openingGroupCharacter) { + if (character === openingGroupCharacter) { // Count group characters groupDepth++ } else if (character === closingGroupCharacter) { @@ -131,7 +127,7 @@ const splitHedString = function (hedString, hedSchemas, groupStartingIndex = 0) * @param {Schemas} hedSchemas The collection of HED schemas. * @param {ParsedHedString} parsedString The object to store parsed output in. * @param {boolean} isTopLevel Whether these tag groups are at the top level. - * @return {object[]} The array of issues. + * @return {Object[]} The array of issues. */ const findTagGroups = function (groupTagsList, hedSchemas, parsedString, isTopLevel) { const issues = [] @@ -309,7 +305,7 @@ const findDelimiterIssuesInHedString = function (hedString) { * Validate the full unparsed HED string. * * @param {string} hedString The unparsed HED string. - * @return {object} String substitution issues and other issues. + * @return {Object} String substitution issues and other issues. */ const validateFullUnparsedHedString = function (hedString) { const [fixedHedString, substitutionIssues] = substituteCharacters(hedString) @@ -332,11 +328,11 @@ const mergeParsingIssues = function (previousIssues, currentIssues) { } /** - * Parse a full HED string into a object of tag types. + * Parse a full HED string into an object of tag types. * * @param {string} hedString The full HED string to parse. * @param {Schemas} hedSchemas The collection of HED schemas. - * @returns {[ParsedHedString|null, object]} The parsed HED tag data and an object containing lists of parsing issues. + * @returns {[ParsedHedString|null, Object]} The parsed HED tag data and an object containing lists of parsing issues. */ const parseHedString = function (hedString, hedSchemas) { const fullStringIssues = validateFullUnparsedHedString(hedString) @@ -344,8 +340,8 @@ const parseHedString = function (hedString, hedSchemas) { fullStringIssues.syntax = [] return [null, fullStringIssues] } - const parsedString = new ParsedHedString(hedString) const [hedTagList, splitIssues] = splitHedString(hedString, hedSchemas) + const parsedString = new ParsedHedString(hedString) parsedString.topLevelTags = findTopLevelTags(hedTagList, hedSchemas, parsedString) const tagGroupIssues = findTagGroups(hedTagList, hedSchemas, parsedString, true) const parsingIssues = Object.assign(fullStringIssues, splitIssues) @@ -360,7 +356,7 @@ const parseHedString = function (hedString, hedSchemas) { * * @param {string[]} hedStrings A set of HED strings. * @param {Schemas} hedSchemas The collection of HED schemas. - * @return {[ParsedHedString[], object]} The parsed HED strings and any issues found. + * @return {[ParsedHedString[], Object]} The parsed HED strings and any issues found. */ const parseHedStrings = function (hedStrings, hedSchemas) { return hedStrings