Bug 486372 - Incorrect syntax highlighting of PHP strings that contain an opening bracket
Summary: Incorrect syntax highlighting of PHP strings that contain an opening bracket
Status: RESOLVED FIXED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (show other bugs)
Version: unspecified
Platform: Other Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-01 01:13 UTC by Stéphane Aulery
Modified: 2024-08-22 16:05 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
The error in pictures (74.44 KB, image/png)
2024-05-01 01:13 UTC, Stéphane Aulery
Details
Code reproducing the error (2.12 KB, application/x-php)
2024-05-01 01:14 UTC, Stéphane Aulery
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stéphane Aulery 2024-05-01 01:13:47 UTC
Created attachment 169053 [details]
The error in pictures

The code snippet below illustrates the problem. Any occurrence of \{ inside a string causes a false coloring in the block between curly brackets following it.

   /**
     * Create a preg pattern for checking presence of a WIKINDX_NO_SORT value at the beginning of a string.
     *
     * If empty($noSortArray), then we use WIKINDX_NO_SORT (and assume that WIKINDX_NO_SORT has been checked for content).
     * Otherwise, $noSortArray is from admin::configure::updateNoSort()
     *
     * @param array $noSortArray Default is []
     *
     * @return string
     */
    function noSortPattern(
        array $noSortArray = [],
    ): string
    {
    	if (empty($noSortArray)) {
    		$noSortArray = \UTF8\mb_explode(',', WIKINDX_NO_SORT);
    	}
		foreach ($noSortArray as $patt) {
			$patt = preg_quote($patt, '@');
			$pattern[] = "^($patt)\\s";
			$pattern[] = "^(\{$patt)\\s";
			$pattern[] = "^(<.*>)($patt)\\s(.*)(<.*>)";
			$pattern[] = "^(<.*>)(\{$patt)\\s?(.*)(<.*>)";
			$pattern[] = "^(<.*>)($patt)(.*)(<.*>)\\s";
			$pattern[] = "^(<.*>)(\{$patt)(.*)(<.*>)\\s";
		}

		return '@' . implode('|', $pattern) . '@Usiu';
	}
    /**
     * Write a hashed version of a user password in users table
     *
     * Implementation history: see \UTILS\verifyUserPassword()
     *
     * @param SQL $db An SQL object
     * @param string $usersId A user Id
     * @param string $usersPassword A clear password to encrypt/hash
     */
    function writeUserPassword(
        \SQL $db,
        int $usersId,
        string $usersPassword,
    ): void
    {
        $hash = \password_hash($usersPassword, PASSWORD_DEFAULT);
        $updateArray["usersPassword"] = $hash;
        
        $usertable = "users";
        // TODO(LkpPo): remove this conditon when the upgrade code of step 57 (6.4.7) is retired.
        if (!$db->tableExists($usertable))
        {
            $usertable = "wkx_users";
        }
        
        $db->formatConditions(["usersId" => $usersId]);
        $db->update($usertable, $updateArray);
    }


STEPS TO REPRODUCE
1. 
2. 
3. 

OBSERVED RESULT


EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 Stéphane Aulery 2024-05-01 01:14:58 UTC
Created attachment 169054 [details]
Code reproducing the error
Comment 2 Stéphane Aulery 2024-05-01 01:18:20 UTC
Checked with Kate 24.07.70 on Windows 11
Comment 3 Christoph Cullmann 2024-08-22 16:05:12 UTC
Git commit d6e2fdf3841dc46c370cd2f5756566cd1e5a82c3 by Christoph Cullmann, on behalf of Jonathan Poelen.
Committed on 22/08/2024 at 16:01.
Pushed by cullmann into branch 'master'.

PHP: add \{ in double quote string as a Backslash Code

M  +1    -0    autotests/folding/highlight.php.fold
M  +1    -0    autotests/html/highlight.php.dark.html
M  +1    -0    autotests/html/highlight.php.html
M  +1    -0    autotests/input/highlight.php
M  +1    -0    autotests/reference/highlight.php.ref
M  +2    -2    data/syntax/php.xml

https://invent.kde.org/frameworks/syntax-highlighting/-/commit/d6e2fdf3841dc46c370cd2f5756566cd1e5a82c3