Support from Acquia helps fund testing for Drupal Acquia logo

Comments

boombatower’s picture

Assigned: Unassigned » boombatower
Status: Active » Needs review
FileSize
2.51 KB
9.64 KB

debug

webchick’s picture

Plus eleventy billion! Marked #639372: Debug() should output with <code> tags as a duplicate.

However, we need to be concerned about security here. While on IRC Jimmy confirmed that this only affects the dsm() triggered by either debug() or PHP errors, not "normal" drupal_set_message()s (so for example, you can't stick JS in a node title), it still seems like it'd be possible to piggy-back malicious code and get the admin to execute it. For example, SQL errors will read out the part of the query that failed, so if you manage to stick '<script>alert('xss');</script>' or similar into a field someplace near a failure, it seems like you could inject malicious JS code... or worse. :\

Status: Needs review » Needs work

The last submitted patch failed testing.

boombatower’s picture

Status: Needs work » Needs review
FileSize
12.97 KB
16.79 KB
1.37 KB

Much simpler version that only displays messages with pre formatting on drupal_set_message() and not in watchdog log. It also will not pre format numbers or simple strings, only objects or arrays. The HTML is also clean so you can look at it there without all the HTML entities which are very annoying.

debug message
debug html

Still not sure if we want to do highlighted string...use highligh_string() php function and var_export(). Looks nice.

boombatower’s picture

FileSize
1.03 KB

Or better yet.

Could also add same sort of logic to code that makes simpletest assertions.

boombatower’s picture

FileSize
7.54 KB

With highligh_string().

highlight string

Damien Tournoud’s picture

Error messages are actually HTML in PHP, while exception messages are plain-text (totally brain-dead...).

Try:

trigger_error("A &amp; B");
throw new Exception("A &amp; B");

You will get:

Notice: A & B in /shared/Drupal/Core/d7/titi.php on line 2

Fatal error: Uncaught exception 'Exception' with message 'A &amp; B' in /shared/Drupal/Core/d7/titi.php:3
Stack trace:
#0 {main}
thrown in /shared/Drupal/Core/d7/titi.php on line 3

So we should be consistent with this, and stop encoding error messages. That should help this patch move forward.

boombatower’s picture

Sure, so now do we also want

 or highlight_string() to make it readable...this is more a side-note to the origin behind this issue.
boombatower’s picture

FileSize
4.36 KB

Reworked my patch with DamZ's and only included

 change for non-scalar values since hightlight_string() would require an exception made to filtering due to inline styles. Had to change filter_xss() to filter_xss_admin() to allow 
 tag.
boombatower’s picture

FileSize
4.27 KB

Add check_plain() in debug() and remove left over comment.

boombatower’s picture

FileSize
4.34 KB

Wrong place for check_plain()...lots of little mistakes.

Status: Needs review » Needs work

The last submitted patch, 642160-debug.patch, failed testing.

boombatower’s picture

Status: Needs work » Needs review
FileSize
9.43 KB

Updating a few things and a test.

mlncn’s picture

Status: Needs review » Reviewed & tested by the community

Tested on the latest Drupal HEAD just now. Still applies, and looks so beautiful on the screen and in logs.

I really hope this can still go in... it does have a plus eleventy-billion from webchick ;-) Note that this is also a concern expressed by several developers in #822714: Add <pre> tags to debug() For me, it felt very, very wrong to tell readers of the Drupal book i'm writing on, or for anyone else to do this, "Drupal 7 includes a debug() function, which is a great convenience when developing (or debugging). Unfortunately, its output runs together when displayed such that it is hard to see the structure of a complex array. Viewing the source code shows the structure but with the distraction of escaped HTML character entities. We can see nested arrays better by using the Devel module's dpr(), dvr(), or dkr() functions; a var_export() or print_r() function call wrapped in <pre> tags in a drupal_set_message() as above; or, of course, a debugger (see chapter {develenv})."

boombatower’s picture

Priority: Normal » Major

Seems fair since I and most people I have talked to dislike the output very much.

Re-test to make sure no ill effects.

boombatower’s picture

#13: 642160-debug.patch queued for re-testing.

boombatower’s picture

Still good.

mlncn’s picture

Good stuff, boombatower. Thanks for the patch. Tagging as a developer experience issue.

yched’s picture

Oh, yes, pretty please...

Damien Tournoud’s picture

Works for me, too.

webchick’s picture

Category: task » bug
Status: Reviewed & tested by the community » Needs work

Great work! I consider this a bug fix, since the current function is well-intentioned but doesn't actually work, really.

I tested this with the following:

<?php
debug
('your mom');
debug(array('your' => 'mom', 'my' => 'dad'));
debug("<script>alert('xss');</script>");
?>

I verified that both before and after this patch this correctly escapes stuff both on-screen and in watchdog, which was a problem in one of the earlier patches that I reviewed, iirc.

The only thing I'd suggest is wrapping the scalar value in <pre> ... </pre> as well. It looks a bit inconsistent now:

Some are pre and some are not

klausi’s picture

Subscribing, coming from #822714: Add <pre> tags to debug()

mlncn’s picture

The escaping single quotation marks in the output is a little weird. Personally, i'd change that before trying to make strings etc. output in the same font as arrays and objects. Note that pre tags will always mean at least three-line messages if there is a label.

carlos8f’s picture

Status: Needs work » Needs review
FileSize
9.95 KB
45.74 KB
44.34 KB

Same as #13, but wrapping in <pre> for all variable types, as @webchick suggested.

carlos8f’s picture

FileSize
9.38 KB

of course, removing the debug() calls would be a good idea. /facepalm

boombatower’s picture

Status: Needs review » Reviewed & tested by the community

:)

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Great. Committed to HEAD!

Status: Fixed » Closed (fixed)
Issue tags: -DX (Developer Experience)

Automatically closed -- issue fixed for 2 weeks with no activity.