Ticket #2990 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

Inline Upload Image Size Attribute Problem For "Using Original"

Reported by: intoxination Assigned to: anonymous
Priority: high Milestone: 2.0.7
Component: Administration Version: 2.0.6
Severity: normal Keywords: upload image has-patch commit
Cc:

Description

In the inline-uploading.php, when you select to use the original and send it to the editor, the height attribute is still included in the img tag, making the image appear as a thumbnail.

This problem seems to be isolated to IE only and the problem appears to come from the lack of quotes around the attribute value (in this case height). The simple workaround I have right now is to add the following line into the sendToEditor Javascript function (around line 431):

After:

h = o.innerHTML.replace(new RegExp?('\\s*(.*?)\\s*$', ), '$1'); // Trim

Add:

h = h.replace(new RegExp?(' (width|height)=.*?', 'g'), ); // Drop size constraints

This strips the height and width constraints without quotes.

I have noticed this problem in versions 2.0 and up (including 2.04).

Attachments

inlineuploadIEfix.patch (0.9 kB) - added by intoxination on 01/06/07 15:19:04.

Change History

08/30/06 19:33:16 changed by Loknsiv

  • keywords set to upload image.
  • status changed from new to closed.
  • resolution set to fixed.

I met the same problem and found the causes and solution:

The following statement around line 432 is used to add quotation marks and it can't work properly:

h = h.replace(new RegExp(' (class|title|width|height|id|onclick|onmousedown)=([^\'"][^ ]*)( |/|>)', 'g'), ' $1="$2"$3'); // Enclose attribs in quotes

For example, if the string h is as below:

<img id=image1 height=96 alt=0011.jpg src="http://www.example.com/sample.png" width=128>

After the replacement it should be something as below:

<img id="image1" height="96" alt="0011.jpg" src="http://www.example.com/sample.png" width="128">

But in fact, for the replace statement can't work properly, the string h will be something as below after the replacement:

<img id="image1" height=96 alt=0011.jpg src="http://www.example.com/sample.png" width="128">

Just use the following replace statement instead of the original one can solve the problem perfectly:

h = h.replace(new RegExp(' (class|title|width|height|id|onclick|onmousedown)=([^\'"][^ ]*)( |/|>)', 'g'), ' $1="$2"$3'); // Enclose attribs in quotes

I hope I can explain the causes more clearly, but I'm Chinese and although I know something clearly but I could not express it clearly, so I can only give the examples and the solution, hoping anyone met the same problem could understand my solution.

08/30/06 22:24:13 changed by Nazgul

  • status changed from closed to reopened.
  • resolution deleted.

Somebody should create a patch and include it in trunk, before marking it as fixed. Because just closing it as fixed the code won't be included in the next version.

01/06/07 12:46:13 changed by smalldust

  • priority changed from normal to high.
  • version changed from 2.0.4 to 2.0.6.
  • milestone set to 2.0.7.

I downloaded 2.0.6 today but still found this bug.

The root cause of this bug is, in line 434 of wp-admin/inline-upload.php there is such a statement:

h = h.replace(new RegExp?(' (class|title|width|height|id|onclick|onmousedown)=([\'"][ ]*)( |/|>)', 'g'), ' $1="$2"$3'); // Enclose attribs in quotes

which is supposed to be able to enclose all attributes in quotes.

But read it carefully, you will know it requires a blank char before the attribute name, and also a blank or / or > after the value of the attribute.

So when there are more than 1 attributes need to be enclosed here, eg

<img id=image01 height=90 .... >

because there is only 1 blank character between "id=image01" and "height=90", and it will be eaten up when "id=image01" is matched. So, "height=90" won't be matched because of the lack of blank character before it.

To solve this problem, I suggest replace the aforementioned statement with this one:

h = h.replace(new RegExp?(' (class|title|width|height|id|onclick|onmousedown)=([\'"][ ]*)(?=( |/|>))', 'g'), ' $1="$2"'); // Enclose attribs in quotes

In this statement, I use the lookahead pattern(?=) to exclude the character after the value of attribute.

01/06/07 12:56:23 changed by smalldust

By the way, this bug can be only reproduced in IE; in firefox everything works well.

That is because, in firefox the innerHTML property returns the inner Html with every values of attribute already enclosed with double quotations. So the enclosing statement did nothing with it.

01/06/07 15:19:04 changed by intoxination

  • attachment inlineuploadIEfix.patch added.

01/06/07 15:21:54 changed by intoxination

Thanks smalldust. I meant to reopen this yesterday after I found it was never fixed and had to go through and modify and re-upload inline-uploading on 5 different sites. Your regex needed one small modification in it, but with that it is now working in IE7 and FF2. Hopefully a developer will commit this to 2.0.7, as this problem has existed since at least 2.0.2 (that I can remember).

01/09/07 08:18:56 changed by mdawaffe

  • keywords changed from upload image to upload image has-patch commit.

Patch is good to go. 2.0 branch only: not an issue in trunk.

01/09/07 08:25:41 changed by ryan

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [4706]) Inline uploader fix from smalldust. fixes #2990