-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix single quotes not being escaped in strings
- Loading branch information
Showing
17 changed files
with
296 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { FilterTranslatorCollection } from "./types"; | ||
import { escapeODataString } from "./utils"; | ||
|
||
export const defaultTranslators: FilterTranslatorCollection = { | ||
"contains": (schema, field, op, value) => { | ||
if ((schema.type && schema.type !== "string") || typeof value !== "string") { | ||
console.warn(`Warning: operation "contains" is only supported for fields of type "string"`); | ||
return false; | ||
} | ||
if (schema.caseSensitive === true) { | ||
return `contains(${field}, '${escapeODataString(value)}')`; | ||
} else { | ||
return `contains(tolower(${field}), tolower('${escapeODataString(value)}'))`; | ||
} | ||
}, | ||
|
||
"null": (schema, field, op, value) => { | ||
return `${field} eq null`; | ||
}, | ||
|
||
"notnull": (schema, field, op, value) => { | ||
return `${field} ne null`; | ||
}, | ||
|
||
"default": (schema, field, op, value) => { | ||
if (schema.type === "date") { | ||
return `date(${field}) ${op} ${value}`; | ||
} else if (schema.type === "datetime") { | ||
return `${field} ${op} ${value}`; | ||
} else if (schema.type === "boolean") { | ||
return `${field} ${op} ${value}`; | ||
} else if (!schema.type || schema.type === "string" || typeof value === "string") { | ||
if (schema.caseSensitive === true) { | ||
return `${field} ${op} '${escapeODataString(value)}'`; | ||
} else { | ||
return `tolower(${field}) ${op} tolower('${escapeODataString(value)}')`; | ||
} | ||
} else { | ||
return `${field} ${op} ${value}`; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.