Skip to main content

Bug Tracker

Side navigation

#13351 closed bug (notabug)

Opened January 30, 2013 07:00AM UTC

Closed January 30, 2013 01:36PM UTC

Last modified March 28, 2014 03:52PM UTC

Syntax error, unrecognized expression with whitespace

Reported by: daniel@danielcarvalho.com 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/

Attachments (0)
Change History (6)

Changed January 30, 2013 07:06AM UTC by anonymous comment:1

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

It just has one simple tab of whitespace.

Replying to [ticket:13351 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/

Changed January 30, 2013 07:11AM UTC by anonymous comment:2

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/

Changed January 30, 2013 07:19AM UTC by daniel@danielcarvalho.com comment:3

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

Changed January 30, 2013 01:36PM UTC by dmethvin comment:4

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.

Changed February 07, 2013 01:52PM UTC by dmethvin comment:5

#13408 is a duplicate of this ticket.

Changed March 28, 2014 03:52PM UTC by CodedMonkey comment:6

Replying to [comment:4 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?