Skip to content

Php Braces Matcher triggers an infinite loop for embedded php text with ":" character wrapped in parenthesis or brackets #7803

@haidubogdan

Description

@haidubogdan

Apache NetBeans version

Apache NetBeans 23

What happened

I've worked on a plugin for blade templates which required Php Embeddings.

During the development I always had an issue that the plugin freeze when the file contained an php embedded text with ":" character.
Ex:

@test($x ?: $y)

Any action like delete, typing on this snippet would trigger a complete freeze for Netbeans.

Language / Project Type / NetBeans Component

PHP

How to reproduce

Have a custom language which will contain Php Embedding language like PHPTokenId.languageInPHP().
Have a text wrapped in parenthesis or brackets which will contain a colon character ":".

@test($x ?: $y)

Any action like delete, typing on this snippet would trigger a freeze.

In order to help with the fix / debugging I've created a forked netbeans branch from my blade plugin on https://github.com/haidubogdan/netbeans/tree/php_blade_for_brace_matcher_issue

Did this work correctly in an earlier version?

Apache NetBeans 18

Operating System

Windows OS

JDK

17

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

After some investigation I found the issue to be on PhpBracesMatcher.
On line 113 there is a condition that when the text contains a ":" character a while loop will be executed as long it detects a PHP_TOKEN lexer token. Parenthesis or brackets are matched as PHP_TOKEN PhpTokenId.
In a full embedded context this would be fine as the first token for a php lexer is always "<?" but in a Php inLanguage embedded context like we can have for blade templates the text with ":" character wrapped in parenthesis will trigger an infinite loop when Php Braces matching is called.

image

Are you willing to submit a pull request?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    PHP[ci] enable extra PHP tests (php/php.editor)kind:bugBug report or fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions