Ticket #3834 (closed enhancement: wontfix)
Selector syntax errors should give better messages
| Reported by: | ajpotts | Owned by: | john |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | selector | Version: | 1.4.4 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I had a bit of a mangled selector on one of my pages which 1.2.6 simply skipped over, but completely kills 1.3.
I should add that I'm aware with 1.3 the correct response should be "Syntax error, unrecognized expression". But I got a far more impenetrable error.
Full test case here: https://www.partyark.co.uk/html/jquery1.3rc2-bug.html
Change History
comment:1 Changed 4 years ago by john
- need changed from Review to Test Case
- Version set to 1.3
- Milestone changed from 1.3 to 1.3.1
comment:2 Changed 4 years ago by dmethvin
- Keywords errors added; unrecognized removed
- need changed from Test Case to Patch
- Type changed from bug to enhancement
- Summary changed from Failure on selector syntax error to Selector syntax errors should give better messages
The error is "a[3] is undefined". As you pointed out, $('.box(:not:has(:radio:checked))') is not valid syntax. jQuery doesn't try to give a nice error message for arbitrary selector syntax errors. I'll recategorize this as a enhancement request for better error handling.
comment:3 Changed 4 years ago by WanderingZombie
I had a lot of problems in IE upgrading from 1.2.6 to 1.3.0 as the following statement did not result in "Syntax error, unrecognized expression: @href=http" being shown when the following statement executed.
$("a[@href=http]").not("a[@href= http://"+location.hostname+"]").each( blah )
Changing
throw "Syntax error, unrecognized expression: " + expr;
to
alert("Syntax error, unrecognized expression: " + expr);
allowed me to see the error and easily fix it by removing the @'s.
But why did I get an uncaught throw error in the first place?
comment:4 Changed 3 years ago by dmethvin
- Keywords needsreview added; selector syntax errors removed
- Status changed from new to open
comment:5 Changed 3 years ago by dmethvin
@WanderingZombie, something was probably catching and discarding the error via try/catch, but not having the code it's impossible to tell.
comment:6 Changed 2 years ago by snover
Current versions of Sizzle don’t throw errors and just return an object with zero elements. Not sure if that is intentional or not.
comment:7 Changed 2 years ago by snover
- Priority changed from minor to low
- Version changed from 1.3 to 1.4.4
- Milestone 1.3.1 deleted
comment:8 Changed 2 years ago by dmethvin
- Status changed from open to closed
- Resolution set to wontfix
As we move towards using the browser's native querySelectorAll implementations, there won't be a lot we can do to improve error messages in Sizzle. It might be possible to do better error checking via a plugin but I don't think we'd put it in the production code.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
