Skip to content

Commit

Permalink
Revert "Revert "@W-15920576 Jh/bug fix string null validation (#269)" (
Browse files Browse the repository at this point in the history
…#272)" (#273)

This reverts commit b6696a2.
  • Loading branch information
jonnyhork authored Jun 12, 2024
1 parent b6696a2 commit 0ac827d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/soql-builder-ui/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion packages/soql-builder-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/soql-builder-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 7 additions & 0 deletions packages/soql-model/src/validators/stringValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
9 changes: 5 additions & 4 deletions packages/soql-model/src/validators/stringValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down

0 comments on commit 0ac827d

Please sign in to comment.