Skip to content

Commit b8e1222

Browse files
committed
Remove unsafe json parsing
1 parent 3074f58 commit b8e1222

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"babel-loader": "^10.0.0",
4141
"bootstrap": "^5.3.8",
4242
"core-js": "^3.16.0",
43+
"json5": "^2.2.3",
4344
"lit": "^3.3.1",
4445
"pdfjs-dist": "^5.3.93",
4546
"rimraf": "^6.0.1",

test/manual/version-tester/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import Vue from 'vue/dist/vue.esm.browser.js';
1+
import JSON5 from 'json5';
22
import { Modal } from 'bootstrap';
3-
4-
function looseJsonParse(obj) {
5-
return Function('"use strict";return (' + obj + ')')();
6-
}
3+
import Vue from 'vue/dist/vue.esm.browser.js';
74

85
const h2pVersions = [ '0.12.1', '0.12.0', '0.11.3', '0.11.2', '0.11.1', '0.11.0', '0.10.3', '0.10.2', '0.10.1', '0.10.0', '0.9.3' ];
96
const iframeHtmlInitial = `<html>
@@ -149,13 +146,13 @@ const app = new Vue({
149146
},
150147
makePdf ({ isDefault } = {}) {
151148
const { html2pdf, target } = this.setupMake('html2pdf');
152-
const h2pOptions = looseJsonParse(isDefault ? h2pOptionsDefault : this.h2pOptions);
149+
const h2pOptions = JSON5.parse(isDefault ? h2pOptionsDefault : this.h2pOptions);
153150

154151
html2pdf(target, h2pOptions);
155152
},
156153
makeCanvas ({ isDefault } = {}) {
157154
const { html2canvas, target } = this.setupMake('html2canvas');
158-
const h2cOptions = looseJsonParse(isDefault ? h2cOptionsDefault : this.h2cOptions);
155+
const h2cOptions = JSON5.parse(isDefault ? h2cOptionsDefault : this.h2cOptions);
159156

160157
html2canvas(target, h2cOptions).then(canvas => {
161158
this.canvas = canvas;

0 commit comments

Comments
 (0)