Skip to content

Commit

Permalink
Validate query string
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 20, 2022
1 parent 9887ea3 commit 3db655d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/config/normalize/lib/wild_wild_parser/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ const throwTokenError = function (queryArray, token, message) {
)
}

// Validate query string is a string
export const validateQueryString = function (queryString) {
if (!isQueryString(queryString)) {
throw new Error('it must be a string.')
}
}

// Empty query strings are ambiguous and not allowed
export const validateEmptyQuery = function ({ arrays }) {
if (arrays.length === 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/config/normalize/lib/wild_wild_parser/query.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validateEmptyQuery } from './normalize.js'
import { validateEmptyQuery, validateQueryString } from './normalize.js'
import {
ESCAPE,
ARRAY_SEPARATOR,
Expand All @@ -12,6 +12,8 @@ import { getStringTokenType } from './tokens/main.js'
// Use imperative logic for performance
// eslint-disable-next-line complexity
export const parseQueryString = function (queryString) {
validateQueryString(queryString)

const state = getInitialState()

// eslint-disable-next-line fp/no-loops
Expand Down

0 comments on commit 3db655d

Please sign in to comment.