PHP input format -> syntax checking
Hi, as you know, there is no way to recover from syntax errors in PHP code a user submits (either as nodes or for example in custom block visibility settings). I'm trying to figure out, if it would be possible to send the code to drupal_eval with javascript and prevent form submission if an error is returned. What do you think? -Tadej
Hi, As long as the submitted code does not cause a fatal error, you should be able to eval the code with drupal_eval and catch any errors with a custom error handler. The trick will be in writing the error handler. http://api.drupal.org/api/4.7/function/drupal_eval http://us3.php.net/manual/en/ref.errorfunc.php ~Rob Tadej Baša wrote:
Hi, as you know, there is no way to recover from syntax errors in PHP code a user submits (either as nodes or for example in custom block visibility settings). I'm trying to figure out, if it would be possible to send the code to drupal_eval with javascript and prevent form submission if an error is returned. What do you think?
-Tadej
-- ---------------------------------------------------------- It is by Caffeine alone that I set my mind in motion It is by the beans of Java, that my thoughts acquire speed The hands acquire shakes; the shakes become a warning It is by Caffeine alone that I set my mind in motion
Robert Wohleb pravi:
Hi,
As long as the submitted code does not cause a fatal error, that's exactly what I want to prevent. e.g. a missing ')' (parse error) in custom block visibility causes the whole site to break.
- Tadej
you should be able to eval the code with drupal_eval and catch any errors with a custom error handler. The trick will be in writing the error handler.
http://api.drupal.org/api/4.7/function/drupal_eval http://us3.php.net/manual/en/ref.errorfunc.php
~Rob
Tadej Baša wrote:
Hi, as you know, there is no way to recover from syntax errors in PHP code a user submits (either as nodes or for example in custom block visibility settings). I'm trying to figure out, if it would be possible to send the code to drupal_eval with javascript and prevent form submission if an error is returned. What do you think?
-Tadej
On 8/21/06, Tadej Baša <tadej.basa@gmail.com> wrote:
Robert Wohleb pravi: that's exactly what I want to prevent. e.g. a missing ')' (parse error) in custom block visibility causes the whole site to break.
Have you tested this? I believe the functionality you desire (site alerts the user to the error but generally continues to work) is already available. There may be some specific cases where that is not the case but I know that haven't found any yet. I just used the following code in a node that was formatted with the php input filter: <?php print("this is fine"); print("this is surely borken" ?> And got the following result: "Parse error: syntax error, unexpected ';' in /home/.beanor/knaddiso/uagdse.com/includes/common.inc(1175) : eval()'d code on line 7" The rest of the site works fine. Which version are you using? Regards, Greg -- Greg Knaddison | Growing Venture Solutions Denver, CO | http://growingventuresolutions.com Technology Solutions for Communities, Individuals, and Small Businesses
Good this is brought up again. Op maandag 21 augustus 2006 18:24, schreef Greg Knaddison - GVS:
Have you tested this? I believe the functionality you desire (site alerts the user to the error but generally continues to work) is already available. There may be some specific cases where that is not the case but I know that haven't found any yet.
I once made an issue for this, because AFAIK a fatal error will still break a lot of Drupal sites. I am not sure if this can be fixed by changing some of the PHP ini configuration. In any case, here is the issue: http://drupal.org/node/40505 Bèr
Good this is brought up again.
Op maandag 21 augustus 2006 18:24, schreef Greg Knaddison - GVS:
Have you tested this? �I believe the functionality you desire (site alerts the user to the error but generally continues to work) is already available. �There may be some specific cases where that is not the case but I know that haven't found any yet.
I once made an issue for this, because AFAIK a fatal error will still break a lot of Drupal sites. I am not sure if this can be fixed by changing some of the PHP ini configuration. In any case, here is the issue: http://drupal.org/node/40505
B�r
Fatal errors cause the whole PHP script to exit, so there is no way to address in a nice way. I think I read somewhere that trapping fatal errors will be available in PHP 6, but until then, the nicest solution I can think of is sending the code to drupal_eval via javascript, detect if drupal_eval died and if so, prevent form submission (or at least warn the user). -Tadej
In node forms, won't the preview button do what you want? You'd get an error during preview instead of saving the error to the database. I'll bet someone who knows the form API inside out could enforce that when php input format is selected, changes must be previewed before submitted. -Dave On Tuesday 22 August 2006 06:03, Tadej Baša wrote:
Fatal errors cause the whole PHP script to exit, so there is no way to address in a nice way.
On 8/22/06, Dave Cohen <drupal@dave-cohen.com> wrote:
In node forms, won't the preview button do what you want? You'd get an error during preview instead of saving the error to the database.
That is true on nodes, which is what I was originally posting and thinking about. On rereading Tadej's emails I realize that Tadej is referring to the admin/block page which doesn't have a preview so fatal errors kill your site and you have to fix it from within the DB (a guess). Currently Drupal just has a stern warning that messing with the PHP code for a block can really mess up your site. Two other possible solutions are the aforementioned javascript drupal_eval check OR using previews for any page that has a php input format. Using javascript has the drawback of not working for all browsers. Previews have the drawback of being relatively slow/painful. I'm not sure there's really a better solution than the one we've got (stern warnings). Regards, Greg -- Greg Knaddison | Growing Venture Solutions Denver, CO | http://growingventuresolutions.com Technology Solutions for Communities, Individuals, and Small Businesses
Currently Drupal just has a stern warning that messing with the PHP code for a block can really mess up your site. Two other possible solutions are the aforementioned javascript drupal_eval check OR using previews for any page that has a php input format. Using javascript has the drawback of not working for all browsers. Previews have the drawback of being relatively slow/painful. I'm not sure there's really a better solution than the one we've got (stern warnings).
you can do a syntax check and not eval the code: php -l is the command line way. there is probably a non command line way. i don't like actually running the code via ajax or preview since the code might actually DO something.
On 8/22/06, Moshe Weitzman <weitzman@tejasa.com> wrote:
you can do a syntax check and not eval the code: php -l is the command line way. there is probably a non command line way. i don't like actually running the code via ajax or preview since the code might actually DO something.
There was a non-command line way to do it from 5.0.0 all the way to 5.0.4 and then it was removed :( Anyway, this is now a feature request: http://drupal.org/node/80103 Regards, Greg -- Greg Knaddison | Growing Venture Solutions Denver, CO | http://growingventuresolutions.com Technology Solutions for Communities, Individuals, and Small Businesses
My second reply must have been lost as I haven't seen it. Maybe my FROM field was wack and the mailing list is holding it up. Anyways... There is a difference between fatal errors and parse errors. Fatal errors tend to involve resource handles, memory allocation, etc. The method I described should work to detect parse errors. ~Rob Tadej Baša wrote:
Robert Wohleb pravi:
Hi,
As long as the submitted code does not cause a fatal error, that's exactly what I want to prevent. e.g. a missing ')' (parse error) in custom block visibility causes the whole site to break.
- Tadej
you should be able to eval the code with drupal_eval and catch any errors with a custom error handler. The trick will be in writing the error handler.
http://api.drupal.org/api/4.7/function/drupal_eval http://us3.php.net/manual/en/ref.errorfunc.php
~Rob
Tadej Baša wrote:
Hi, as you know, there is no way to recover from syntax errors in PHP code a user submits (either as nodes or for example in custom block visibility settings). I'm trying to figure out, if it would be possible to send the code to drupal_eval with javascript and prevent form submission if an error is returned. What do you think?
-Tadej
-- ---------------------------------------------------------- It is by Caffeine alone that I set my mind in motion It is by the beans of Java, that my thoughts acquire speed The hands acquire shakes; the shakes become a warning It is by Caffeine alone that I set my mind in motion
participants (6)
-
Bèr Kessels -
Dave Cohen -
Greg Knaddison - GVS -
Moshe Weitzman -
Robert Wohleb -
Tadej Baša