eval

Why do people say that javascript eval() is evil but you get no objections against setTimeout and setInterval etc?

前提是你 提交于 2019-11-27 23:39:54
问题 if I am not mistaken eval executes valid code in a given string eval("alert('hey')"); and setTimeout("alert('hey')",1000); does just about the same thing, only with a timer. is set timeout just as risky as eval? 回答1: I'd say you hear the same objections. setTimeout (with string and not function parameters) is pretty much the same as eval. If possible, setTimeout(function(){ alert ("hey") ; }, 1000); 回答2: Because when people say "eval", they mean "eval and any function that is more or less

PHP: Equivalent of include using eval

╄→尐↘猪︶ㄣ 提交于 2019-11-27 22:56:20
If the code is the same, there appears to be a difference between: include 'external.php'; and eval('?>' . file_get_contents('external.php') . '<?php'); What is the difference? Does anybody know? I know the two are different because the include works fine and the eval gives an error. When I originally asked the question, I wasn't sure whether it gave an error on all code or just on mine (and because the code was eval ed, it was very hard to find out what the error meant). However, after having researched the answer, it turns out that whether or not you get the error does not depend on the code

Safety of Python 'eval' For List Deserialization

心已入冬 提交于 2019-11-27 22:32:16
Are there any security exploits that could occur in this scenario: eval(repr(unsanitized_user_input), {"__builtins__": None}, {"True":True, "False":False}) where unsanitized_user_input is a str object. The string is user-generated and could be nasty. Assuming our web framework hasn't failed us, it's a real honest-to-god str instance from the Python builtins. If this is dangerous, can we do anything to the input to make it safe? We definitely don't want to execute anything contained in the string. See also: Funny blog post about eval safety Previous Question Blog: Fast deserialization in Python

Setting variables by name in Java

筅森魡賤 提交于 2019-11-27 22:11:50
I'm looking to implement something in Java along the lines of: class Foo{ private int lorem; // private int ipsum; public setAttribute(String attr, int val){ //sets attribute based on name } public static void main(String [] args){ Foo f = new Foo(); f.setAttribute("lorem",1); f.setAttribute("ipsum",2); } public Foo(){} } ...where a variable is set based on the variable name without the variable names hard-coded and without using any other data structures. Is this possible? Here's how you might implement setAttribute using reflection (I've renamed the function; there are different reflection

Assigning and removing objects in a loop: eval(parse(paste(

我与影子孤独终老i 提交于 2019-11-27 21:58:15
问题 I am looking to assign objects in a loop. I've read that some form of eval(parse( is what I need to perform this, but I'm running into errors listing invalid text or no such file or directory. Below is sample code of generally what I'm attempting to do: x <- array(seq(1,18,by=1),dim=c(3,2,3)) for (i in 1:length(x[1,1,])) { eval(parse(paste(letters[i],"<-mean(x[,,",i,"])",sep="") } And when I'm finished using these objects, I would like to remove them (the actual objects are very large and

Evaluate math equations from unsafe user input in Python

孤街醉人 提交于 2019-11-27 20:30:07
I have a website where the user enters math equations (expressions) and then those equations are evaluated against data (constants) provided by the website. The math operations needed include symbols, arithmetic operations, min() , max() and some other basic functions. A sample equation could be: max(a * b + 100, a / b - 200) One could simply eval() this using Python, but as we all know this leads compromising the site. What would be the safe approach of doing math equation evaluation? What math equation parsing and evaluation engines there are for Python If one chooses to use Python itself to

How safe is expression evaluation using eval?

久未见 提交于 2019-11-27 19:20:56
问题 I am building a website where I have a need that user should be able to evaluate some expression based from the value in DB tables, instead of using tools like pyparsing etc, I am thinking of using python itself, and have come up with a solution which is sufficient for my purpose. I am basically using eval to evaluate the expression and passing globals dict with empty __builtins__ so that nothing can be accessed and a locals dict for values from DB, if user will need some functions I can pass

C# Eval() support [duplicate]

心已入冬 提交于 2019-11-27 19:07:16
问题 This question already has an answer here: How can I evaluate C# code dynamically? 16 answers we need to evaluate a value in an object in run time while we have a textual statement of the exact member path for example: myobject.firstMember.secondMember[3].text we thought of parsing this textual statement using regex and then evaluate the text value by using reflection but before we do that i wonder if C# support some kind of eval ability? so we won't have to do the parsing ourself. How do

eval()函数的使用

不羁岁月 提交于 2019-11-27 19:07:12
1.eval() 函数作用:可以接受一个字符串str作为参数,并把这个参数作为脚本代码来 执行。 2.参数情况:(1)如果参数是一个表达式,eval() 函数将执行表达式; (2) 如果参数是Javascript语句,eval()将执行 Javascript 语句 3.注意:(如果执行结果是一个值就返回,不是就返回undefined,如果参数不是一 个字符串,则直接返回该参数) 4.语法:eval(string), 5.案例: eval("var a=1");//声明一个变量a并赋值1。 eval("2+3");//执行加运算,并返回运算值。 eval("mytest()");//执行mytest()函数。 eval("{b:2}");//声明一个对象。如果想返回此对象,则需要在对象外面再嵌套一层小括如下:eval("({b:2})"); 注意:使用eval来解析JSON格式字符串的时候,会将{}解析为代码块,而不是对象的字面量 //1.在JSON格式的字符串前面拼接上 "var o =" //2.把JSON格式的字符串使用()括起来,就不会将{}解析为代码块,而是表达式 6.函数作用域:eval()函数并不会创建一个新的作用域,并且它的作用域就是它所在的 作用域,有时候需要将eval()函数的作用域设置为全局,当然可以将eval()在全局作用 域中使用,这个时候可以用window

What's the main benefit of using eval() in JavaScript?

怎甘沉沦 提交于 2019-11-27 18:57:41
I know this may be a newbie question, but I'm curious as to the main benefit of eval() - where would it be used best? I appreciate any info. The eval function is best used: Never. It's purpose is to evaluate a string as a Javascript expression. Example: eval('x = 42'); It has been used a lot before, because a lot of people didn't know how to write the proper code for what they wanted to do. For example when using a dynamic name for a field: eval('document.frm.'+frmName).value = text; The proper way to do that would be: document.frm[frmName].value = text; As the eval method executes the string