Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#23176 closed defect (bug) (fixed)

Inserting media with multiple newlines in caption breaks HTML

Reported by: jonieske's profile jonieske Owned by: azaozz's profile azaozz
Milestone: 3.5.1 Priority: normal
Severity: minor Version: 3.5
Component: Media Keywords: has-patch
Focuses: Cc:

Description

Steps to reproduce:

  1. Open add media dialog in editor to insert image
  2. Select image, enter caption with multiple newlines, eg:

"one
two
three"

  1. Leave alt text field empty
  2. Insert image into post
  3. Save/Update

As a result, HTML code breaks and image isn't displayed. This happens because caption is inserted to alt attribute in case it's empty, and newlines break the markup. Toggling between text and visual modes before initial post save fixes the code though.

Proposed fix:
Remove newlines from content that is automatically inserted to alt attribute.

Attachments (2)

23176.diff (477 bytes) - added by kovshenin 12 years ago.
Replace newlines with spaces before sending to the editor
23176.2.diff (474 bytes) - added by kovshenin 12 years ago.
Replace multiple new lines with one space.

Download all attachments as: .zip

Change History (8)

#1 @kovshenin
12 years ago

  • Cc kovshenin added
  • Keywords needs-patch added

I can reproduce this against trunk. Here's the HTML code that gets generated when inserting the image with a multi-line caption and no alt tag: http://cl.ly/image/3c0d253C3O3a

@kovshenin
12 years ago

Replace newlines with spaces before sending to the editor

#2 follow-up: @SergeyBiryukov
12 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 3.5.1

Confirmed. Appears to be a regression. In 3.4.2, an empty alt attribute wasn't populated with caption, and remained empty after following the steps from the description.

Last edited 12 years ago by SergeyBiryukov (previous) (diff)

#3 in reply to: ↑ 2 ; follow-up: @azaozz
12 years ago

Replying to SergeyBiryukov:

Confirmed too. Perhaps the regex should be:

props.alt.replace( /[\r\n]+/g, ' ' );

so we replace multiple new lines with one space.

#4 in reply to: ↑ 3 @kovshenin
12 years ago

Replying to azaozz: sounds fair :)

@kovshenin
12 years ago

Replace multiple new lines with one space.

#5 @azaozz
12 years ago

  • Owner set to azaozz
  • Resolution set to fixed
  • Status changed from new to closed

In 23298:

Media: when copying from "caption" (textarea) to "alt" (text input) also remove line breaks, props kovshenin, fixes #23176 for trunk

#6 @azaozz
12 years ago

In 23299:

Media: when copying from "caption" (textarea) to "alt" (text input) also remove line breaks, props kovshenin, fixes #23176 for 3.5

Note: See TracTickets for help on using tickets.