Fix string escape single qupte

This commit is contained in:
barsdeveloper
2023-04-03 20:02:58 +02:00
parent 62b3968af3
commit 2380d61bb6
5 changed files with 16 additions and 9 deletions

View File

@@ -148,9 +148,18 @@ describe("Utility class", () => {
expect(Utility.escapeString("")).to.be.equal("")
expect(Utility.unescapeString("")).to.be.equal("")
expect(Utility.escapeString('"')).to.be.equal('\\"')
expect(Utility.unescapeString('\\"')).to.be.equal('"')
expect(Utility.escapeString("'")).to.be.equal("\\'")
expect(Utility.unescapeString("\\'")).to.be.equal("'")
expect(Utility.escapeString(String.raw`\"`)).to.be.equal(String.raw`\\\"`)
expect(Utility.unescapeString(String.raw`\"`)).to.be.equal('"')
expect(Utility.escapeString(String.raw`\'`)).to.be.equal(String.raw`\\\'`)
expect(Utility.unescapeString(String.raw`\'`)).to.be.equal("'")
expect(Utility.escapeString(String.raw`Hello \"World\"`)).to.be.equal(String.raw`Hello \\\"World\\\"`)
expect(Utility.unescapeString(String.raw`Hello \"World\"`)).to.be.equal('Hello "World"')

7
dist/ueblueprint.js vendored
View File

@@ -193,6 +193,7 @@ class Configuration {
}
static selectAllKeyboardKey = "(bCtrl=True,Key=A)"
static smoothScrollTime = 1000 // ms
static stringEscapedCharacters = /['"\\]/g
static trackingMouseEventName = {
begin: "ueb-tracking-mouse-begin",
end: "ueb-tracking-mouse-end",
@@ -740,8 +741,7 @@ class Utility {
/** @param {String} value */
static escapeString(value) {
return value
.replaceAll('\\', '\\\\') // Escape \
.replaceAll('"', '\\"') // Escape "
.replaceAll(new RegExp(`(${Configuration.stringEscapedCharacters.source})`, "g"), '\\$1')
.replaceAll("\n", "\\n") // Replace newline with \n
.replaceAll("\t", "\\t") // Replace tab with \t
}
@@ -751,8 +751,7 @@ class Utility {
return value
.replaceAll("\\t", "\t") // Replace tab with \t
.replaceAll("\\n", "\n") // Replace newline with \n
.replaceAll('\\"', '"') // Escape "
.replaceAll('\\\\', '\\') // Escape \
.replaceAll(new RegExp(`\\\\(${Configuration.stringEscapedCharacters.source})`, "g"), "$1")
}
/** @param {String} value */

File diff suppressed because one or more lines are too long

View File

@@ -169,6 +169,7 @@ export default class Configuration {
}
static selectAllKeyboardKey = "(bCtrl=True,Key=A)"
static smoothScrollTime = 1000 // ms
static stringEscapedCharacters = /['"\\]/g
static trackingMouseEventName = {
begin: "ueb-tracking-mouse-begin",
end: "ueb-tracking-mouse-end",

View File

@@ -299,8 +299,7 @@ export default class Utility {
/** @param {String} value */
static escapeString(value) {
return value
.replaceAll('\\', '\\\\') // Escape \
.replaceAll('"', '\\"') // Escape "
.replaceAll(new RegExp(`(${Configuration.stringEscapedCharacters.source})`, "g"), '\\$1')
.replaceAll("\n", "\\n") // Replace newline with \n
.replaceAll("\t", "\\t") // Replace tab with \t
}
@@ -310,8 +309,7 @@ export default class Utility {
return value
.replaceAll("\\t", "\t") // Replace tab with \t
.replaceAll("\\n", "\n") // Replace newline with \n
.replaceAll('\\"', '"') // Escape "
.replaceAll('\\\\', '\\') // Escape \
.replaceAll(new RegExp(`\\\\(${Configuration.stringEscapedCharacters.source})`, "g"), "$1")
}
/** @param {String} value */