Skip to content

Commit 84e509f

Browse files
authored
@W-15920576 Jh/bug fix string null validation (#269)
1 parent 47547a3 commit 84e509f

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

packages/soql-builder-ui/.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@lwc/lwc/no-async-operation": "off",
1010
"@lwc/lwc/no-inner-html": "warn",
1111
"@lwc/lwc/no-document-query": "warn",
12-
"no-underscore-dangle": "off"
12+
"no-underscore-dangle": "off",
13+
"@typescript-eslint/no-unused-vars": "warn"
1314
}
1415
}

packages/soql-builder-ui/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"license": "BSD-3-Clause",
4545
"main": "dist/",
4646
"scripts": {
47-
"build": "lwc-services build -w webpack.config.js -m production",
47+
"build": "export NODE_OPTIONS=--openssl-legacy-provider && lwc-services build -w webpack.config.js -m production",
4848
"clean": "shx rm -rf package-lock.json && shx rm -rf dist && shx rm -rf node_modules",
4949
"publish:lwc": "npm publish .",
5050
"lint": "eslint ./src",
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

packages/soql-model/src/validators/stringValidator.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ describe('StringValidator should', () => {
1616
it('return valid result for string in single quotes', () => {
1717
expect(validator.validate("'foo'")).toEqual(validResult);
1818
});
19+
20+
it('return valid result when user input is NULL or null', () => {
21+
expect(validator.validate("'null'")).toEqual(validResult);
22+
expect(validator.validate("'NULL'")).toEqual(validResult);
23+
});
24+
1925
it('return not valid result for non-string value', () => {
2026
expect(validator.validate('foo')).toEqual(notValidResult);
2127
});
28+
2229
it('return not valid result for string ending in escaped quote', () => {
2330
expect(validator.validate("'foo\\'")).toEqual(notValidResult);
2431
});

packages/soql-model/src/validators/stringValidator.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import { ValidateResult, Validator } from './validator';
1010
export class StringValidator extends Validator {
1111
public validate(input: string): ValidateResult {
1212
const isValid =
13-
input.length >= 2 &&
14-
input.startsWith("'") &&
15-
input.endsWith("'") &&
16-
!this.isEscaped(input.substring(1, input.length - 1));
13+
(input.length >= 2 &&
14+
input.startsWith("'") &&
15+
input.endsWith("'") &&
16+
!this.isEscaped(input.substring(1, input.length - 1))) ||
17+
input.toLowerCase() === 'null';
1718
const message = isValid ? undefined : Messages.error_fieldInput_string;
1819
return { isValid, message };
1920
}

0 commit comments

Comments
 (0)