Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#13351 closed bug (notabug)

Syntax error, unrecognized expression with whitespace

Reported by: daniel@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.0
Keywords: Cc:
Blocked by: Blocking:

Description

If you do an insertAfter, or even an appendTo for that matter, with an HTML string that has whitespace (tabbed whitespace), you get an error: "Syntax error, unrecognized expression".

This can be remedied by executing jQuery.trim onto the HTML string, but this never used to break in earlier versions of jQuery like v1.7.2. Only the new release v1.9.0. You shouldn't need to do jQuery trim. So older code breaks with zero changes.

Example: http://jsfiddle.net/6XTk2/

Change History (6)

comment:1 in reply to:  description Changed 6 years ago by anonymous

Please see an even more powerful and simple example -> http://jsfiddle.net/6XTk2/2/

It just has one simple tab of whitespace.

Replying to daniel@…:

If you do an insertAfter, or even an appendTo for that matter, with an HTML string that has whitespace (tabbed whitespace), you get an error: "Syntax error, unrecognized expression".

This can be remedied by executing jQuery.trim onto the HTML string, but this never used to break in earlier versions of jQuery like v1.7.2. Only the new release v1.9.0. You shouldn't need to do jQuery trim. So older code breaks with zero changes.

Example: http://jsfiddle.net/6XTk2/

comment:2 Changed 6 years ago by anonymous

Sorry, another update. But this is even worse, it's not even tabbed whitespace, it's ANY whitespace.

A even more powerful example -> http://jsfiddle.net/6XTk2/2/

comment:3 Changed 6 years ago by daniel@…

The last link should be http://jsfiddle.net/6XTk2/3/

comment:4 Changed 6 years ago by dmethvin

Resolution: notabug
Status: newclosed

Yes, that's documented in the upgrade guide. By far, the most common situation where whitespace may appear is when processing an HTML template. For those cases, use $.parseHTML to specify (for both your sake and the sake of anyone else reading the code) whether you intend for scripts to be run in the incoming HTML.

comment:5 Changed 6 years ago by dmethvin

#13408 is a duplicate of this ticket.

comment:6 in reply to:  4 Changed 5 years ago by CodedMonkey

Replying to dmethvin:

Yes, that's documented in the upgrade guide. By far, the most common situation where whitespace may appear is when processing an HTML template. For those cases, use $.parseHTML to specify (for both your sake and the sake of anyone else reading the code) whether you intend for scripts to be run in the incoming HTML.

Why is this documented in the changelogs but not in the normal documentation?

Note: See TracTickets for help on using tickets.