Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
markup
Priority:
Minor
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
21 Aug 2009 at 15:12 UTC
Updated:
16 Aug 2011 at 00:12 UTC
Jump to comment: Most recent file
Comments
Comment #2
TheRec commentedRe-test needed :)
Comment #3
sun.core commented.
Comment #4
TheRec commentedOops, a typo in the title :)
Comment #5
dries commentedLooks like we're mixing isset() and !empty() in that line. Is that intentional?
Comment #6
TheRec commentedRight ! And checking drupal_attributes() returned data like this has no sense, the same check is done in this function... I should have checked the code of drupal_attributes().
It should work better this way... the space is prepended only when image size is not empty and I moved a condition outside the return, which makes it a bit more readable (shorter line).
Comment #8
lilou commentedHEAD is broken.
Comment #9
kars-t commentedtheme_image() did change since the patch. Now we have
If both are empty there still might be two spaces.
But I can't run this through a debugger right now to see what happens there.
Comment #10
effulgentsia commentedhow's this?
Comment #12
effulgentsia commented#10: theme_image_minor_cleanup-555830-10.patch queued for re-testing.
Comment #13
effulgentsia commentedMoving to "markup" queue. Trivial clean up.
Comment #14
sunLet's do this properly, please.
Comment #15
sun/me blinks ;)
Comment #16
sunVariable clean-up.
Comment #17
effulgentsia commenteddrupal_attributes() and check_url() call check_plain(), so this results in 'src', 'alt', and 'title' being check_plain()'d twice.
Powered by Dreditor.
Comment #18
effulgentsia commentedThe "quick fix" tag is a curse.
Comment #19
sunObviously, I've lost track of which functions already call check_plain() and which functions not. :(
Comment #20
effulgentsia commentedcheck_url() calls check_plain() too, so this results in double check_plain(). Do we need to check_url() the result of file_create_url()? Do we have this situation anywhere else: setting a value in an $attributes array to the result of a check_url()?
[EDIT: see also #715142: [beta blocker blocker] Various URLs escaped twice, since check_url() resp. filter_xss_bad_protocol() calls check_plain()]
142 critical left. Go review some!
Comment #21
sunComment #22
jacineI'm really happy to see this patch! Was going to do the same thing over in: #520704: How should theme_image() deal with screen readers not reading the image title attribute?.
Much better.
Comment #23
aspilicious commentedIm not rly sure if I'm helping here but this is a try (just deleted check_url)
Comment #24
sunVery odd. Further findings now in #715142-6: [beta blocker blocker] Various URLs escaped twice, since check_url() resp. filter_xss_bad_protocol() calls check_plain()
Comment #25
effulgentsia commentedPostponing this until we reach a conclusion about what check_url() should do in #715142: [beta blocker blocker] Various URLs escaped twice, since check_url() resp. filter_xss_bad_protocol() calls check_plain().
Comment #26
jacineHmm, I think we need special handling for the alt attribute. It needs to be there (even if it's empty) for accessibility purposes because if it's not, the screen reader will announce "Image with no alt text" and then proceed to read the actual file name. See this page for details.
Comment #27
Everett Zufelt commentedI did a very quick read through the comments here. I agree with @jacine, that if an image is clrearly for presentation (e.g. a spacer) that the alt attribute should = "". However, if an image conveys meaning or purpose than the alt attribute should eiter convey the meaning and purpose or not exist at all. There are cases where the name of the image file, absent an appropriate alt attribute, is more useful that alt = "".
Comment #28
Everett Zufelt commentedtagging
Comment #29
mgiffordI think this will eliminate those instances where the alt tags are the same as the filename, but I don't have an easy way to pull up this function. Is there a recommended way to see the output?
This patch applied fine. I like the additional checks for attributes.
Comment #30
jacine@mgifford this is the function that takes care of outputting all images. It will take care of outputting empty attributes (especially title), and in general it's a very nice clean-up, but it can't solve the these kinds of issues, as it has no context. It just prints out what it's told. Those kinds of issues need to be dealt with at the source. I made a list of possible places that we can improve in that regard here: #520704: How should theme_image() deal with screen readers not reading the image title attribute?.
That said, a good way to test this one is to look at the Syndicate block. The RSS Icon is output using this function.
Before the patch you get:
<img src="http://sky.d7/misc/feed.png" alt="Subscribe to Syndicate" title="" width="16" height="16" />After:
<img src="http://sky.d7/misc/feed.png" alt="Subscribe to Syndicate" width="16" height="16" />Comment #31
mgifford@Jacine, sorry. I was just about to send a follow up note to say that the patch above in #29 is rubbish. The RSS Icon or themes/seven/template.php's sort ascending/descending.
Just started looking at this too late in the evening. The goal in my patch (as rubbish as it was) was simply to do a check to see that the filename wasn't being used as an alt attribute. Thinking about it after looking at #520704: How should theme_image() deal with screen readers not reading the image title attribute? it seemed that it's unlikely that someone would take the time to insert "$theme_path . '/images/arrow-asc.png'" into an alt tag. Seems most likely that someone would absentmindedly just add "arrow-asc.png".
However, I can't see someone doing that anywhere at the code level, even in the contrib directories. It's much more important to check for this in user contributed content. I'm not sure that adding a check for bad alt tag definitions (other than empty or perhaps a space " ") is useful.
I'm in full agreement though about eliminating blank tags! So +1 on #23!
Comment #32
sunBased on recent discussion in the other issue, I think we're safe to apply this change. That is, because this function returns a HTML string, so it is the last theme function in a rendering stack and therefore responsible for sanitizing the URL.
Therefore, re-uploading the last known good patch.
Comment #33
mgiffordAdding special case for alt specified by @Jacine in #26.
Comment #34
effulgentsia commentedHEAD currently has a test (testLXSS()) requiring that l() be safe from XSS attacks. If l() needs to be safe from XSS, then so should theme_image(). Changing this to a requirement that bad protocols be stripped before theme('image') is called should go through a security review. Let's do that review on the other issue, and once the other issue lands, pursue this otherwise nice clean-up of theme_image().
Powered by Dreditor.
Comment #35
effulgentsia commentedI was wrong in #34. l() calls check_plain(), not check_url(). Therefore, it's ok to change theme_image() to do the same. Patch looks good except:
Please remove trailing whitespace from lines, but also, can we shorten this to 1 line:
$attributes['alt'] = !empty($alt) ? $alt : '';Powered by Dreditor.
Comment #36
sunThanks, optimized that.
Comment #37
effulgentsia commentedHow do you feel about this instead? empty() is the wrong check for $alt and $title, as there's no reason to prevent '0'. Also, I'm not crazy about making it impossible to remove the 'alt'. With this patch, passing an explicit 'alt' => NULL removes it, but leaving it unspecified defaults to it being an empty string.
Comment #39
effulgentsia commentedI don't think this is the issue to make the #37 tests pass as a result of a decision to change what 'title' defaults to (from empty string to not being output). Let's do that in #520704: How should theme_image() deal with screen readers not reading the image title attribute?. This patch removes that, tests should pass.
Comment #40
sunI'm against introducing new @todos at this stage. Since !empty() is indeed the wrong condition, we have to implement the isset() and default argument change here.
Comment #42
sunComment #44
Everett Zufelt commentedI haven't followed all of the comments on this issue. However, I will state here that unless alt or title are explicitly set (including being explicitly set to null "") that the attributes should not be generated. When a screen-reader comes across an image with alt="" it performs differently than when the alt attribute is not present. That is, alt="" and an omitted alt attribute are not equivalents as far as accessibility is concerned. Not sure about title, but I would suspect that depending on the screen-reader it would be similar.
Comment #45
effulgentsia commentedThe scope of this issue has evolved, so updating title to match.
Comment #46
sun@Everett: Not sure whether I understood your direction regarding the alt attribute. If none has been defined, should one be output or not? Is a missing alt attribute valid XHTML?
Aside from that, attached patch should finally pass.
Comment #47
Everett Zufelt commented@Sun
There are three options for an image in xhtml
1. alt="description"
2. alt="" this is effectively saying presentation only (separator image, etc.)
3. No alt attribute, this is an image without a description, but which is not explicitly defined as presentational only.
I believe that in xhtml an alt attribute is required for validation, but I am not certain about this. Marking images with alt="" where no alt text is available is very bad for accessibility.
Example:
Comment #48
sunW3C validator says that a missing alt attribute is invalid for XHTML+RDFa 1.0, so I fear there's little that we can do on that.
Comment #49
sunGiven that technical doctype limitation and requirement for an alt attribute, I think we're back to RTBC here.
Comment #50
effulgentsia commentedI agree with the RTBC. This changes 'title' from default of empty string to default of being omitted: this is in line with Everett's recommendation in #44 and has no down side AFAICT. This leaves 'alt' as defaulting to empty string (no change relative to HEAD), which is not Everett's recommendation with respect to accessibility, but is required for W3C validation.
I can appreciate the argument that 'alt' should be omitted by default, requiring code that calls theme('image') to always pass in something for 'alt' (even if empty string), and allowing a W3C validator to catch when that's not done. But that's a change from HEAD that perhaps should be debated in a separate issue? The rest of what's being done in #46 makes a lot of sense, so let's not hold it up.
Comment #51
dries commentedCommitted to CVS HEAD. Thanks.
As a follow-up patch, it might be nice to document why we sometimes use '' vs NULL. We can re-purpose the text from #50 for that.
Comment #52
effulgentsia commentedSome duplication, but given how often this issue is discussed, perhaps this will help cut down on support requests. I'm not an expert on this topic or good at writing concise documentation, so anyone who is: please feel free to suggest edits.
@Everett: I'd love your feedback on this.
Comment #53
sunAwesome.
Comment #54
dries commentedCommitted to CVS HEAD.
Comment #56
effulgentsia commentedFollow-up for D8: #999338: theme_image() alt attribute cannot be passed in $variables['attributes']