Skip to content

Commit de1ed9d

Browse files
committed
fix: value must be a string to test for url operators
1 parent 2bc548e commit de1ed9d

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/getValue.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,31 +122,33 @@ const getValue = (element) => {
122122
value = localStorage.getItem('clientId')
123123
else if (value === '$session_id')
124124
value = localStorage.getItem('session_id')
125-
else if (value.startsWith('$search')) {
126-
const searchParams = new URLSearchParams(window.location.search);
127-
if (value.includes('.')) {
128-
value = searchParams.get(value.split('.')[1]);
129-
} else {
130-
const paramsObject = {};
131-
132-
// Iterate over all key-value pairs and add them to the object
133-
for (const [key, value] of searchParams) {
134-
paramsObject[key] = value;
125+
else if (typeof value === 'string') {
126+
if (value.startsWith('$search')) {
127+
const searchParams = new URLSearchParams(window.location.search);
128+
if (value.includes('.')) {
129+
value = searchParams.get(value.split('.')[1]);
130+
} else {
131+
const paramsObject = {};
132+
133+
// Iterate over all key-value pairs and add them to the object
134+
for (const [key, value] of searchParams) {
135+
paramsObject[key] = value;
136+
}
137+
value = paramsObject
135138
}
136-
value = paramsObject
137-
}
138139

139-
} else if ([
140-
'$href',
141-
'$origin',
142-
'$protocol',
143-
'$host',
144-
'$hostname',
145-
'$port',
146-
'$pathname',
147-
'$hash'
148-
].includes(value)) {
149-
value = window.location[value.substring(1)]
140+
} else if ([
141+
'$href',
142+
'$origin',
143+
'$protocol',
144+
'$host',
145+
'$hostname',
146+
'$port',
147+
'$pathname',
148+
'$hash'
149+
].includes(value)) {
150+
value = window.location[value.substring(1)]
151+
}
150152
}
151153

152154
let replace = element.getAttribute('value-replace');

0 commit comments

Comments
 (0)