Problem/Motivation

The functionality that replaces an <img> element in a submitted comment when it is malformed is a bit buggy.

What happens is that the original <img> tag that the user typed in their comment is replaced by the parser with an "error-not-found" image.

The problem is that newly inserted image still uses the width and height attributes that were attached to the original image. On inspecting the error-image's properties, I see that it's a totally new image - this is indicated by the fact that the alt attribute says, "Only local images are allowed." when the original code I'd typed was empty.

Please view the attached screenshot: buggy_non-local-image_error-placeholder.png.

Proposed resolution

It would be great if the parser (be it a text-filter or whatever) didn't reuse the width and height properties from the original post's image and instead used the real properties of the error-placeholder image. See before and after code below:

Before

<img src="/misc/watchdog-error.png" width="933" height="681" alt="Only local images are allowed." title="Only local images are allowed.">

After

<img src="/misc/watchdog-error.png" width="18" height="18" alt="Only local images are allowed." title="Only local images are allowed.">

Remaining tasks

 

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Update the issue summary Instructions Completed in #6
Add automated tests Instructions #11
Manually test the patch Novice Instructions Completed in #9
Embed before and after screenshots in the issue summary Novice Instructions Completed in #9
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards Instructions Completed in #9/#12

User interface changes

The inserted error image will be its natural size.

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anandkp’s picture

Issue summary: View changes
drumm’s picture

Project: Drupal.org customizations » Local image input filter
Version: 7.x-3.x-dev » 7.x-1.x-dev
drumm’s picture

Title: Update issue-queue comment html filter so that it outputs "missing image" placeholder correctly. » Set width & height for "missing image" placeholder
Project: Local image input filter » Drupal core
Version: 7.x-1.x-dev » 8.x-dev
Component: Code » filter.module
Category: Bug report » Task
Issue tags: +affects drupal.org

This issue should be tackled in core, then backported.

Wim Leers’s picture

Issue tags: +Novice, +php-novice
c31ck’s picture

Status: Active » Needs review
FileSize
1.06 KB

Wrote a patch that determines the width and height of the error image and sets them.

Steven Jones’s picture

Issue summary: View changes
Wim Leers’s picture

Status: Needs review » Needs work

@c31ck: thanks! Looking good :)

Please also update FilterHtmlImageSecureTest.

+++ b/core/modules/filter/filter.module
@@ -1202,10 +1202,15 @@ function _filter_html_image_secure_process($text) {
+

Extraneous newline.

c31ck’s picture

Assigned: Unassigned » c31ck
mErilainen’s picture

Issue summary: View changes
FileSize
928 bytes
64.76 KB
41.21 KB

Removed empty line.
Added before and after images.
Updated issue queue.
Maybe c31ck is working on the tests?

c31ck’s picture

Hi mErilainen, yes I'll work on the tests sometime this week.

c31ck’s picture

Assigned: c31ck » Unassigned
Status: Needs work » Needs review
FileSize
1.67 KB

Changed the test so that the width and height are checked as well.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks!

Steven Jones’s picture

Issue summary: View changes

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 2d4cdae and pushed to 8.x. Thanks!

  • alexpott committed 2d4cdae on 8.x
    Issue #2125769 by c31ck, mErilainen | anandps: Set width...
tvn’s picture

This should be backported now to D7?

drumm’s picture

Project: Drupal core » Local image input filter
Version: 8.x-dev » 7.x-1.x-dev
Component: filter.module » Code
Status: Fixed » Patch (to be ported)

Yes.

Steven Jones’s picture

Status: Patch (to be ported) » Needs review
FileSize
1.42 KB

Here's a patch for the D7 version of the module.

  • sun committed 225a0f3 on authored by Steven Jones
    Issue #2125769 by c31ck, Steven Jones, mErilainen: Set width...
sun’s picture

Project: Local image input filter » Drupal core
Version: 7.x-1.x-dev » 8.x-dev
Component: Code » filter.module

Thanks, committed (for now).

However, technically, this is an API change for the D7 module, since existing alter hooks for the placeholder image will need to be adjusted.

I wonder why we went through the extra processing logic of determining the width/height of the placeholder image, instead of simply removing the width/height attributes?

I also don't see that option in the discussion above?

Wim Leers’s picture

Perhaps it was not considered because images should always have width and height attributes specified, because if they're missing, then that may cause content to be rerendered (and hence it may "jump") once the image is downloaded.

millerbennett’s picture

Status: Needs review » Fixed

While width and height are not required according to spec, I do agree with Wim- not supplying image dimensions causes browsers to re-flow the content around the image which is quite an expensive operation and also causes a visual jump. I believe we can mark this as fixed for now.

Status: Fixed » Closed (fixed)

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