解决Node读取Js文件未设置编码造成的vm.run()运行报错问题和vm.runInContext()方法不存在造成的运行报错问题#79
Open
Gowther wants to merge 1 commit into
Open
解决Node读取Js文件未设置编码造成的vm.run()运行报错问题和vm.runInContext()方法不存在造成的运行报错问题#79Gowther wants to merge 1 commit into
Gowther wants to merge 1 commit into
Conversation
1. 本地Node版本v12.18.3,根据Node官方文档(https://nodejs.org/api/fs.html#fsreaddirsyncpath-options)说明,fs.readFileSync(path, endcoding)方法,不传encoding时方法返回的是二进制的buffer,126行 vm.run(code) 运行时会报错 2. 根据vm2官方文档(https://github.com/patriksimek/vm2)说明,找不到 vm.runInContext()方法, 160 行运行报错 What is the difference between Node's vm and vm2? const vm = require('vm'); vm.runInNewContext('this.constructor.constructor("return process")().exit()'); const {VM} = require('vm2'); new VM().run('this.constructor.constructor("return process")().exit()');
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.What is the difference between Node's vm and vm2?