yelda-webchat 1.1.19 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/yeldaWebchatInjector.js +2 -2
- package/dist/js/yeldaWebchatInjector.js.gz +0 -0
- package/dist/js/yeldaWebchatInjector.js.map +1 -1
- package/dist/js/yeldaWebchatInjector.min.js +2 -2
- package/dist/js/yeldaWebchatInjector.min.js.gz +0 -0
- package/dist/js/yeldaWebchatInjector.min.js.map +1 -1
- package/package.json +1 -1
- package/src/js/yeldaWebchatInjector.js +36 -4
package/package.json
CHANGED
|
@@ -25,6 +25,23 @@ const isStrLikelyEncoded = (str) => {
|
|
|
25
25
|
return hasNonASCII || hasPercentEncoding
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Check whether the string is stringified object
|
|
30
|
+
* @param {String} str
|
|
31
|
+
* @returns {Boolean}
|
|
32
|
+
*/
|
|
33
|
+
const isStringifiedObject = (str) => {
|
|
34
|
+
try {
|
|
35
|
+
// Replace single quotes with double quotes
|
|
36
|
+
const jsonString = str.replace(/'/g, '"')
|
|
37
|
+
// Attempt to parse the string
|
|
38
|
+
const obj = JSON.parse(jsonString)
|
|
39
|
+
return typeof obj === 'object' && obj !== null
|
|
40
|
+
} catch (error) {
|
|
41
|
+
return false // Parsing failed, not a valid JSON string
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
28
45
|
/**
|
|
29
46
|
* Execute the function by name with the arguments
|
|
30
47
|
* @param {String} functionName
|
|
@@ -78,11 +95,19 @@ class YeldaChat {
|
|
|
78
95
|
if (argsStr !== '') {
|
|
79
96
|
let argBuffer = ''
|
|
80
97
|
let parenCount = 0
|
|
98
|
+
const openingBrackets = ['(', '[', '{']
|
|
99
|
+
const closingBrackets = [')', ']', '}']
|
|
100
|
+
let isQuotesOpened = false
|
|
101
|
+
|
|
81
102
|
for (const element of argsStr) {
|
|
82
|
-
|
|
83
|
-
|
|
103
|
+
if (element === `'`) {
|
|
104
|
+
isQuotesOpened = !isQuotesOpened
|
|
105
|
+
}
|
|
84
106
|
|
|
85
|
-
if (element
|
|
107
|
+
if (openingBrackets.includes(element)) parenCount++
|
|
108
|
+
else if(closingBrackets.includes(element)) parenCount--
|
|
109
|
+
|
|
110
|
+
if (element === ',' && parenCount === 0 && !isQuotesOpened) {
|
|
86
111
|
args.push(argBuffer.trim())
|
|
87
112
|
argBuffer = ''
|
|
88
113
|
} else {
|
|
@@ -100,7 +125,7 @@ class YeldaChat {
|
|
|
100
125
|
else if (arg === 'null') return null
|
|
101
126
|
else if (arg.startsWith('[') && arg.endsWith(']')) {
|
|
102
127
|
try {
|
|
103
|
-
return JSON.parse(arg)
|
|
128
|
+
return JSON.parse(JSON.stringify(arg))
|
|
104
129
|
} catch(err) {
|
|
105
130
|
return ''
|
|
106
131
|
}
|
|
@@ -110,9 +135,16 @@ class YeldaChat {
|
|
|
110
135
|
} catch(err) {
|
|
111
136
|
return ''
|
|
112
137
|
}
|
|
138
|
+
} else if (isStringifiedObject(arg)) {
|
|
139
|
+
try{
|
|
140
|
+
return JSON.parse(arg.replace(/'/g, '"'))
|
|
141
|
+
} catch(err) {
|
|
142
|
+
return ''
|
|
143
|
+
}
|
|
113
144
|
}
|
|
114
145
|
return arg.replace(/^['"]|['"]$/g, '') // Remove surrounding quotes if any
|
|
115
146
|
})
|
|
147
|
+
|
|
116
148
|
return { functionName, args }
|
|
117
149
|
}
|
|
118
150
|
|