fix ifinite loop caused by php brace matcher in embedded lexer context#9023
Conversation
php/php.editor/src/org/netbeans/modules/php/editor/PHPBracesMatcher.java
Outdated
Show resolved
Hide resolved
|
@haidubogdan It would be helpful to see an example that causes a loop. While I agree, that a test would be the best case, I think a review can substitute that. Infinite loops are really ugly to test for (at least the failing variant). |
|
@matthiasblaesing |
|
@haidubogdan I'd like to "see" the problem, so instructions how to reproduce (if necessary with code) would be great. |
|
I've created this branch master...haidubogdan:netbeans:t_php_bracematcher_infinite_loop_test It's just for simulating the infinite loop. Context: I have a custom language support (text/x-php-test). |
|
@haidubogdan thank you. It makes sense that this was not caught before as for "normal" PHP situations this problem can't manifest. The scanning stops when the first token with a ID <> So the change makes sense to me. An alternative I would see is to guard the if(! ts.movePrevious()) {
break;
}The What do you think? |
@matthiasblaesing |
2fc6ba1 to
a318ee7
Compare
|
@haidubogdan thanks for the update. Looks cleaner and I appreciate the added test! |
php/php.editor/src/org/netbeans/modules/php/editor/PHPBracesMatcher.java
Outdated
Show resolved
Hide resolved
tmysik
left a comment
There was a problem hiding this comment.
Looks good to me, just a minor comment added (related to the coding style). Thank you
…Php Lexer Language closes apache#7803 Exit brace matcher loop for matching semi-colon-colon braces if token sequence can't movePrevious. Add unit test with custom php embedded language for timeout check on braces matcher. Max execution time 3000 ms.
a318ee7 to
0a3d075
Compare
|
@haidubogdan Thank you! |
This pull request tries to fix issue #7803 .
Php brace matcher used for highlighting (if, foreach ) statements like
<?php if ($x): ?> ...<?php endif;?>loops through tokens until it finds the opening parenthesis.The current implementation can trigger a infinite loop for a embedded usage of Php lexer as there is no exit mechanism beside the PhpTokenId.TOKEN check.