eval

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control

徘徊边缘 提交于 2019-11-26 14:04:45
问题 I am getting the following error Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. but all I am trying to do is inside a ASP.NET REPEATER Control <% if ( Eval("Message").ToString() == HttpContext.Current.Profile.UserName) %> <% { %> <asp:ImageButton runat="server" etc.... /> <% } %> 回答1: The syntax is <%# Eval("...") %> You could do something like <asp:ImageButton Visible='<%# ShowImg(Eval(Container.DataItem,"Message")) %>' /> and

Avoiding the infamous “eval(parse())” construct

徘徊边缘 提交于 2019-11-26 13:58:58
问题 Ok, so I'm running some loops to process data stored in list objects. Ever mindful of the infamous fortune admonishment not to use eval(parse(mystring)) , I came up with this: Rgames> bar $foo $foo$fast [1] 1 2 3 4 5 $foo$slow [1] 6 7 8 9 10 $oof $oof[[1]] [1] 6 7 8 9 10 $oof[[2]] [1] 1 2 3 4 5 Rgames> rab<-'bar' Rgames> do.call('$',list(as.name(rab),'oof')) [[1]] [1] 6 7 8 9 10 [[2]] [1] 1 2 3 4 5 Typically I'd be selecting a list (of which bar is one such) and then one element of the list

Python eval: is it still dangerous if I disable builtins and attribute access?

瘦欲@ 提交于 2019-11-26 12:58:40
问题 We all know that eval is dangerous, even if you hide dangerous functions, because you can use Python\'s introspection features to dig down into things and re-extract them. For example, even if you delete __builtins__ , you can retrieve them with [c for c in ().__class__.__base__.__subclasses__() if c.__name__ == \'catch_warnings\'][0]()._module.__builtins__ However, every example I\'ve seen of this uses attribute access. What if I disable all builtins, and disable attribute access (by

Why does ast.literal_eval(&#39;5 * 7&#39;) fail?

江枫思渺然 提交于 2019-11-26 12:30:38
问题 Why does the literal evaluation of 5 * 7 fail, while 5 + 7 doesn\'t? import ast print(ast.literal_eval(\'5 + 7\')) # -> 12 print(ast.literal_eval(\'5 * 7\')) # -> Traceback (most recent call last): ... ValueError: malformed node or string: <_ast.BinOp object at ...> The documentation doesn\'t explain this. I found that problem after answering this question on SO: Getting the result of a string. 回答1: ast.literal_eval() accepts + in the evaluated data because 5+2j (complex number * ) are valid

Haskell: how to evaluate a String like “1+2”

核能气质少年 提交于 2019-11-26 12:28:24
问题 Actually I have some formula like \"x + y\" , which is a String . I managed to replace the x/y variable with specific values like \"1.2\" , which is still String type. Now I have expression like \"1 + 2\" . So the problem is how to evaluate a expression of a string type and get the result. ps: I wanna sth like read , that can directly convert the whole string expression instead of handling the operator (+/-,etc) case by case. Is that possible? 回答1: Your question leaves a lot of room for

Indirect variable assignment in bash

泪湿孤枕 提交于 2019-11-26 12:23:33
Seems that the recommended way of doing indirect variable setting in bash is to use eval : var=x; val=foo eval $var=$val echo $x # --> foo The problem is the usual one with eval : var=x; val=1$'\n'pwd eval $var=$val # bad output here (and since it is recommended in many places, I wonder just how many scripts are vulnerable because of this...) In any case, the obvious solution of using (escaped) quotes doesn't really work: var=x; val=1\"$'\n'pwd\" eval $var=\"$val\" # fail with the above The thing is that bash has indirect variable reference baked in (with ${!foo} ), but I don't see any such

When (if ever) is eval NOT evil?

本秂侑毒 提交于 2019-11-26 12:22:22
I've heard many places that PHP's eval function is often not the answer . In light of PHP 5.3's LSB and closures we're running out of reasons to depend on eval or create_function . Are there any conceivable cases where eval is the best (only?) answer in PHP 5.3? This question is not about whether eval is evil in general, as it obviously is not. Summary of Answers: Evaluating numerical expressions (or other "safe" subsets of PHP) Unit testing Interactive PHP "shell" Deserialization of trusted var_export Some template languages Creating backdoors for administers and/or hackers Compatibility with

Safely sandbox and execute user submitted JavaScript?

◇◆丶佛笑我妖孽 提交于 2019-11-26 12:11:14
问题 I would like to have the ability to let users submit arbitrary JavaScript code, which is then sent to a Node.JS server and safely executed before the output is sent back to multiple clients (as JSON). The eval function comes to mind, but I know this has multiple security concerns (the user submitted code would be able to access Node\'s File API, etc). I have seen some projects like Microsoft Web Sandbox and Google Caja which allow execution of sanitized markup and script (for embedding third

eval command in Bash and its typical uses

旧街凉风 提交于 2019-11-26 11:57:36
After reading the bash man pages and with respect to this post . I am still having trouble understanding what exactly the eval command does and which would be its typical uses. For example if we do: bash$ set -- one two three # sets $1 $2 $3 bash$ echo $1 one bash$ n=1 bash$ echo ${$n} ## First attempt to echo $1 using brackets fails bash: ${$n}: bad substitution bash$ echo $($n) ## Second attempt to echo $1 using parentheses fails bash: 1: command not found bash$ eval echo \${$n} ## Third attempt to echo $1 using 'eval' succeeds one What exactly is happening here and how do the dollar sign

Process mathematical equations in php

别等时光非礼了梦想. 提交于 2019-11-26 11:34:50
问题 A user is allowed to enter any mathematical equation they like (with one variable): x + 5 1 - x/2 (x/3) * (56/13) These are stored as strings in the database. When they are retrieved I need to substitute \'x\' for a number and check the value of the equation. How could I do this? I was considering writing a parser to deconstruct the strings and turn them into equations, however this sounds expensive and problematic. The other option is to pass them through eval (but I\'m not a great fan of