Skip to content

Commit 9a9a817

Browse files
committed
Add @nyariv/sandboxjs dependency and refactor function execution to use sandbox
1 parent 5345430 commit 9a9a817

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@nuxt-alt/auth": "^3.1.6",
2121
"@nuxt-alt/http": "^1.7.10",
2222
"@nuxt-alt/proxy": "^2.5.8",
23+
"@nyariv/sandboxjs": "^0.8.23",
2324
"@pinia/nuxt": "^0.5.1",
2425
"@quasar/extras": "^1.16.9",
2526
"@vueuse/router": "^10.7.2",

src/composables/useColumnsIdentities.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { QTableProps } from 'quasar'
22
import type { components } from '#build/types/service-api'
3+
import Sandbox from '@nyariv/sandboxjs'
34

45
type Identity = components['schemas']['IdentitiesDto']
56

@@ -31,15 +32,23 @@ const daysjs = useDayjs()
3132

3233
function processFieldValue(row: any, field: any) {
3334
if (field.type === 'function') {
34-
return eval(field.value);
35+
const sandbox = new Sandbox();
36+
const exec = sandbox.compile('return ' + field.value, true);
37+
38+
return exec({ row }).run();
3539
}
40+
3641
return row[field];
3742
}
3843

3944
function processFormat(value: any, format: any) {
4045
if (format && format.type === 'function') {
41-
return eval(format.value);
46+
const sandbox = new Sandbox();
47+
const exec = sandbox.compile('return ' + format.value, true);
48+
49+
return exec({ value }).run();
4250
}
51+
4352
return Array.isArray(value) ? value?.join(', ') : value;
4453
}
4554

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,11 @@
11051105
vite-plugin-checker "^0.6.4"
11061106
vue-bundle-renderer "^2.0.0"
11071107

1108+
"@nyariv/sandboxjs@^0.8.23":
1109+
version "0.8.23"
1110+
resolved "https://registry.yarnpkg.com/@nyariv/sandboxjs/-/sandboxjs-0.8.23.tgz#6903ff28343988f12f142f79c577fbd226288920"
1111+
integrity sha512-OaD3i0czFTZzQFQdwgFVEqNyZVK19N6Jzmx/LjmDc+kiV751FQ2h3xscYkAeY4jfau2vZTZau+xR8fpkKrv/Ng==
1112+
11081113
"@parcel/watcher-android-arm64@2.4.1":
11091114
version "2.4.1"
11101115
resolved "https://registry.yarnpkg.com/@parcel/watcher-android-arm64/-/watcher-android-arm64-2.4.1.tgz#c2c19a3c442313ff007d2d7a9c2c1dd3e1c9ca84"

0 commit comments

Comments
 (0)