Make WordPress Core

Opened 20 years ago

Closed 19 years ago

#2990 closed defect (bug) (fixed)

Inline Upload Image Size Attribute Problem For "Using Original"

Reported by: intoxination's profile intoxination Owned by:
Milestone: 2.0.7 Priority: high
Severity: normal Version: 2.0.6
Component: Administration Keywords: upload image has-patch commit
Focuses: 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 (1)

inlineuploadIEfix.patch (931 bytes) - added by intoxination 19 years ago.

Download all attachments as: .zip

Change History (8)

#1 @Loknsiv
20 years ago

  • Keywords upload image added
  • Resolution set to fixed
  • Status changed from new to closed

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.

#2 @Nazgul
20 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

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.

#3 @smalldust
19 years ago

  • Milestone set to 2.0.7
  • Priority changed from normal to high
  • Version changed from 2.0.4 to 2.0.6

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.

#4 @smalldust
19 years ago

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.

#5 @intoxination
19 years ago

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).

#6 @mdawaffe
19 years ago

  • Keywords has-patch commit added

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

#7 @ryan
19 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

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

Note: See TracTickets for help on using tickets.