From 0ac827dfcb0f7eab45412dbb37ac1c99fea20745 Mon Sep 17 00:00:00 2001 From: Jonny Hork Date: Wed, 12 Jun 2024 14:57:36 -0600 Subject: [PATCH] Revert "Revert "@W-15920576 Jh/bug fix string null validation (#269)" (#272)" (#273) This reverts commit b6696a21bf23ae47943c24e4296204624f654501. --- packages/soql-builder-ui/.eslintrc.json | 3 ++- packages/soql-builder-ui/package.json | 2 +- packages/soql-builder-ui/tsconfig.json | 1 + .../soql-model/src/validators/stringValidator.test.ts | 7 +++++++ packages/soql-model/src/validators/stringValidator.ts | 9 +++++---- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/soql-builder-ui/.eslintrc.json b/packages/soql-builder-ui/.eslintrc.json index 4006118f..963d114f 100644 --- a/packages/soql-builder-ui/.eslintrc.json +++ b/packages/soql-builder-ui/.eslintrc.json @@ -9,6 +9,7 @@ "@lwc/lwc/no-async-operation": "off", "@lwc/lwc/no-inner-html": "warn", "@lwc/lwc/no-document-query": "warn", - "no-underscore-dangle": "off" + "no-underscore-dangle": "off", + "@typescript-eslint/no-unused-vars": "warn" } } diff --git a/packages/soql-builder-ui/package.json b/packages/soql-builder-ui/package.json index 970eec06..8084aa28 100644 --- a/packages/soql-builder-ui/package.json +++ b/packages/soql-builder-ui/package.json @@ -44,7 +44,7 @@ "license": "BSD-3-Clause", "main": "dist/", "scripts": { - "build": "lwc-services build -w webpack.config.js -m production", + "build": "export NODE_OPTIONS=--openssl-legacy-provider && lwc-services build -w webpack.config.js -m production", "clean": "shx rm -rf package-lock.json && shx rm -rf dist && shx rm -rf node_modules", "publish:lwc": "npm publish .", "lint": "eslint ./src", diff --git a/packages/soql-builder-ui/tsconfig.json b/packages/soql-builder-ui/tsconfig.json index e69de29b..0967ef42 100644 --- a/packages/soql-builder-ui/tsconfig.json +++ b/packages/soql-builder-ui/tsconfig.json @@ -0,0 +1 @@ +{} diff --git a/packages/soql-model/src/validators/stringValidator.test.ts b/packages/soql-model/src/validators/stringValidator.test.ts index ef787fae..cfdcbdfd 100644 --- a/packages/soql-model/src/validators/stringValidator.test.ts +++ b/packages/soql-model/src/validators/stringValidator.test.ts @@ -16,9 +16,16 @@ describe('StringValidator should', () => { it('return valid result for string in single quotes', () => { expect(validator.validate("'foo'")).toEqual(validResult); }); + + it('return valid result when user input is NULL or null', () => { + expect(validator.validate("'null'")).toEqual(validResult); + expect(validator.validate("'NULL'")).toEqual(validResult); + }); + it('return not valid result for non-string value', () => { expect(validator.validate('foo')).toEqual(notValidResult); }); + it('return not valid result for string ending in escaped quote', () => { expect(validator.validate("'foo\\'")).toEqual(notValidResult); }); diff --git a/packages/soql-model/src/validators/stringValidator.ts b/packages/soql-model/src/validators/stringValidator.ts index 966072ae..6d0f356c 100644 --- a/packages/soql-model/src/validators/stringValidator.ts +++ b/packages/soql-model/src/validators/stringValidator.ts @@ -10,10 +10,11 @@ import { ValidateResult, Validator } from './validator'; export class StringValidator extends Validator { public validate(input: string): ValidateResult { const isValid = - input.length >= 2 && - input.startsWith("'") && - input.endsWith("'") && - !this.isEscaped(input.substring(1, input.length - 1)); + (input.length >= 2 && + input.startsWith("'") && + input.endsWith("'") && + !this.isEscaped(input.substring(1, input.length - 1))) || + input.toLowerCase() === 'null'; const message = isValid ? undefined : Messages.error_fieldInput_string; return { isValid, message }; }