Skip to content

Commit

Permalink
fix: further adjustments of regex
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskari committed Sep 16, 2024
1 parent 4c0a7e2 commit e782c71
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/components/Extensibility/ExtensibilityDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export const ExtensibilityDetailsCore = ({
resource,
});

console.log(schema);
console.log(resMetaData);

const jsonata = useJsonata({});

const description = useCreateResourceDescription(resourceDescription);
Expand Down
7 changes: 5 additions & 2 deletions src/components/Extensibility/helpers/jsonataWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import { AuthDataState, authDataState } from 'state/authDataAtom';

export const escapeKebabCase = (expr: string) => {
return expr.replace(
/(?<!`)(?<!["'0-9a-zA-Z_])([a-zA-Z0-9_]+(?:-[a-zA-Z0-9_]+)+)(?!["'`0-9])/g,
'`$1`',
/(["'`])(?:\\.|.)*?\1|([a-zA-Z_][\w-]*)(-\w+)/g,

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with '"' and containing many repetitions of '\a'.
(match, quotedString, identifier, hyphenPart) => {
if (quotedString) return match;
return `\`${identifier}${hyphenPart}\``;
},
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ describe('escapeKebabCase', () => {
expect(escapeKebabCase(expression)).toBe('$root.spec.myRegularPath');
});

it('kebab path 1', () => {
it('kebab path', () => {
const expression = '$root.spec.my-kebab-path';
expect(escapeKebabCase(expression)).toBe('$root.spec.`my-kebab-path`');
});

it('kebab path, regular path', () => {
it('kebab path and regular path', () => {
const expression = '$root.spec.my-kebab-path.subPath';
expect(escapeKebabCase(expression)).toBe(
'$root.spec.`my-kebab-path`.subPath',
Expand All @@ -25,11 +25,6 @@ describe('escapeKebabCase', () => {
);
});

it('special path', () => {
const expression = '$root.spec.some-$special-path';
expect(escapeKebabCase(expression)).toBe('$root.spec.`some-$special-path`');
});

it('direct follow-up 1', () => {
const expression = '$root.spec.my-kebab-path.subPath!=true';
expect(escapeKebabCase(expression)).toBe(
Expand Down

0 comments on commit e782c71

Please sign in to comment.