Skip to content

Commit

Permalink
fixed escaping for copy option
Browse files Browse the repository at this point in the history
  • Loading branch information
arslanbekova committed Jul 18, 2023
1 parent 4413481 commit 116e6cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/common/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ export const floatToPercent = (value: number) => {
export const copyToClipboard = (text: string) => {
// "\\\\3" - needed to get "\3" in 'eval()'
const transformedText = text
.replace(/'/g, "\\'")
.replace(/\'/g, "\\\\'")
.replace(/\n/g, "\\n")
.replace(/#\\3/g, "#\\\\3")
.replace(/=\\'\\3/g, "=\\'\\\\3") // two different cases for \\3 to avoid affecting something else...
.replace(/\\/g, "\\\\")
.replace(/"/g, '\\"');
.replace(/\"/g, '\\\\"');
chrome.devtools.inspectedWindow.eval(`copy('${transformedText}')`);
};

Expand Down
7 changes: 3 additions & 4 deletions src/pageServices/contentScripts/generationData.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,14 @@ export const getGenerationAttributes = () => {

const isSelectorByGeneratorString = typeof selectorByGenerator === "string";
const isSelectorByFinderString = typeof selectorByFinder === "string";
const transformSelector = (selector) => selector.replace(/"/g, "'");

if (isSelectorByGeneratorString && isSelectorByFinderString) {
const selector = selectorByGenerator.length < selectorByFinder.length ? selectorByGenerator : selectorByFinder;
return transformSelector(selector);
return selector;
} else if (!isSelectorByFinderString && isSelectorByGeneratorString) {
return transformSelector(selectorByGenerator);
return selectorByGenerator;
} else if (!isSelectorByGeneratorString && isSelectorByFinderString) {
return transformSelector(selectorByFinder);
return selectorByFinder;
} else {
return "CSS selector generation was failed";
}
Expand Down

0 comments on commit 116e6cf

Please sign in to comment.