Bug Tracker

Modify

Ticket #11153 (closed bug: fixed)

Opened 17 months ago

Last modified 14 months ago

jQuery 1.7 Strips Carriage Returns in IE 8

Reported by: drlongghost@… Owned by:
Priority: low Milestone: 1.8
Component: attributes Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

In versions of jQuery prior to 1.7, new nodes which are inserted preserve all carriage returns in IE 8. This is now broken in 1.7.

Test Case page:  http://jsfiddle.net/27DGw/3/

In the above test case, in all browsers except IE 8, the value which is alerted is "One\nTwo". In IE 8, the alerted value is "OneTwo".

Note that when you change the jquery library to a version < 1.7, IE 8 returns the expected, correct value.

The workaround I'm forced to adopt for the app I'm working on is to use non-jquery, native javascript methods to append items to the DOM in cases where the carriage returns are significant.

Change History

comment:1 Changed 16 months ago by sindresorhus

  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to misc

From the .text() docs:

Due to variations in the HTML parsers in different browsers, the text returned may vary in newlines and other white space.

An  performance refactor to the getText sizzle method, which is used by .text, was landed in 1.7, which means it now uses textContent/innerText to get the text of elements. Previously it went through all the elements nodeValue property, which was less performant. getText strips carriage returns in IE, don't know exactly why, probably for consistency?

Anyhow, you could use innerText directly, which will convert <br /> to newline automatically:  http://jsfiddle.net/mofle/GQXJF/

comment:2 Changed 16 months ago by sindresorhus

#11262 is a duplicate of this ticket.

comment:3 Changed 15 months ago by anonymous

FWIW, I do feel this is a legitimate bug that should be addressed. While it may seem incongruous, the inconsistent behavior complicates cross-browser implementation of contenteditable interfaces, among other things.

Could the performance enhancement you mentioned use a conditional so it defaults to the slower, more correct method for IE <= 8?

comment:4 Changed 15 months ago by dmethvin

  • Component changed from misc to attributes
  • Milestone changed from None to 1.8

Yes, this was due to the changes to Sizzle.getText(), probably the only way to fix it is to go back to the old way (at minimum for oldIE). Let's review and decide for 1.8.

comment:5 Changed 14 months ago by timmywil

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

Update Sizzle and add test for sizzle getText fix. Removes usage of innerText. Fixes #11153.

Changeset: a29d482894a844724f4386f2fed0edf9cf70c069

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.