Skip to content

Commit

Permalink
Merge pull request #1727 from jdi-testing/issue_1588-escaping-special…
Browse files Browse the repository at this point in the history
…-text-locator-characters

Issue 1588: escaping special text locator characters
  • Loading branch information
KateDronova authored May 1, 2024
2 parents 5341d8b + 9cd164d commit 37d338e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "JDN — Page Object Generator",
"description": "JDN – helps Test Automation Engineer to create Page Objects in the test automation framework and speed up test development",
"devtools_page": "index.html",
"version": "3.15.27",
"version": "3.15.28",
"icons": {
"128": "icon128.png"
},
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jdn-ai-chrome-extension",
"version": "3.15.27",
"version": "3.15.28",
"description": "jdn-ai chrome extension",
"scripts": {
"start": "webpack --watch --env devenv",
Expand Down
6 changes: 6 additions & 0 deletions src/features/locators/components/LocatorsTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { selectCurrentPageObject } from '../../pageObjects/selectors/pageObjects
import { selectPresentLocatorsByPO } from '../selectors/locatorsByPO.selectors';
import { selectFilteredLocators } from '../selectors/locatorsFiltered.selectors';
import { isLocatorListPage } from '../../../app/utils/helpers';
import { fullEscapeLocatorString, checkForEscaped } from '../utils/escapeLocatorString';
import { LocatorType } from '../../../common/types/common';
import type RcTree from 'rc-tree';
import cn from 'classnames';

Expand Down Expand Up @@ -118,6 +120,10 @@ export const LocatorsTree: React.FC<LocatorTreeProps> = ({ locatorIds, viewProps
const { element_id, children, parent_id, jdnHash, searchState, depth } = element;
const locator = locatorsMap[element_id];

if (locator.locatorType === LocatorType.linkText && !checkForEscaped(locator.locatorValue.output)) {
locator.locatorValue.output = fullEscapeLocatorString(locator.locatorValue.output);
}

const className = cn({
'jdn__tree-item--selected': locator?.isGenerated && isLocatorListPage(currentPage),
'jdn__tree-item--active': locator?.active,
Expand Down
16 changes: 16 additions & 0 deletions src/features/locators/utils/escapeLocatorString.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
export const escapeLocatorString = (selector: string): string => {
return selector.replace(/(["'\\])/g, '\\$1');
};

export const fullEscapeLocatorString = (str: string = ''): string => {
return str
.replaceAll(/\\/g, '\\\\') // escape backslash
.replaceAll(/\"/g, '\\"') // escape double quotes
.replaceAll(/\'/g, "\\'") // escape single quotes
.replaceAll(/\t/g, '\\t') // escape tabs
.replaceAll(/\n/g, '\\n') // escape newlines
.replaceAll(/\r/g, '\\r') // escape carriage returns
.replaceAll(/\f/g, '\\f'); // escape form feeds
};

export const checkForEscaped = (str: string = ''): boolean => {
const found = str.match(/\\/);
return found ? true : false;
};

0 comments on commit 37d338e

Please sign in to comment.