From: Joe Higton Date: Wed, 13 Oct 2010 07:33:41 +0000 (+0100) Subject: Catch unmatched "[" in selector parser with a helpful error X-Git-Tag: release_0.009004~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=bd4e2ca023a71bbc87d89bb52e7ad7e9b417a98d Catch unmatched "[" in selector parser with a helpful error --- diff --git a/lib/HTML/Zoom/SelectorParser.pm b/lib/HTML/Zoom/SelectorParser.pm index d3a505a..9bc7bc3 100644 --- a/lib/HTML/Zoom/SelectorParser.pm +++ b/lib/HTML/Zoom/SelectorParser.pm @@ -99,7 +99,12 @@ sub _raw_parse_simple_selector { sub { exists $_[0]->{attrs}{$attribute}; } - } + }; + + # none of the above matched, try catching some obvious errors: + + # indicate unmatched square bracket: + /\G\[[^\]]*/gc and $_[0]->_blam('Unmatched ['); } } diff --git a/t/selectors.t b/t/selectors.t index 46e8439..09875ad 100644 --- a/t/selectors.t +++ b/t/selectors.t @@ -96,18 +96,16 @@ ok( check_select( '[prop=moo]'), '[attr=bar]' ); is( check_select('span[class=career],[prop=moo]'), 2, 'Multiple selectors: el[attr=bar],[attr=foo]'); -TODO:{ - local $TODO = 'Fix selector error messages'; - # selector parse error test: - eval{ - HTML::Zoom->from_html('') - ->select('[att=bar') - ->replace_content('cats') + +# selector parse error test: +eval{ + HTML::Zoom->from_html('') + ->select('[att=bar') + ->replace_content('cats') ->to_html; - }; - like( $@, qr/Error parsing dispatch specification/, - 'Malformed attribute selector results in a helpful error' ); }; +like( $@, qr/Error parsing dispatch specification/, + 'Malformed attribute selector ([att=bar) results in a helpful error' ); =pod