Skip to content

CustomvarFlat: Don't ingnore special chars when splitting#1375

Merged
nilmerg merged 1 commit into
mainfrom
fix/regex-of-preg-split
May 21, 2026
Merged

CustomvarFlat: Don't ingnore special chars when splitting#1375
nilmerg merged 1 commit into
mainfrom
fix/regex-of-preg-split

Conversation

@sukhwinder33445
Copy link
Copy Markdown
Contributor

@sukhwinder33445 sukhwinder33445 commented May 20, 2026

Two issues were fixed in the split regex:

  1. Special characters before . were ignored:
    The old regex only split on . when directly preceded by a wordcharacter (\w), causing splits to be missed when . was preceded by special characters like whitespace, / or $.
    Result before: foo /.bar.one => ['foo /.bar', 'one']
    Result after: foo /.bar.one => ['foo /', 'bar', 'one']

  2. Brackets mid-word were incorrectly split:
    The old regex split before any [, causing keys like con[0]cat to be split incorrectly.
    Now splits before [ only when it's a standalone array index — meaning ] is followed by ., another [, or end of string.

    1. Dot (.) : disk[0].size => ['disk', '[0]', 'size']
    2. Bracket([): disk[0][1] => ['disk', '[0]', '[1]']
    3. String end: disk[0] => ['disk', '[0]']

    Result before: con[0]cat => ['con', '[0]cat']
    Result after: con[0]cat => ['con', '[0]', 'cat']

@cla-bot cla-bot Bot added the cla/signed CLA is signed by all contributors of a PR label May 20, 2026
@sukhwinder33445 sukhwinder33445 requested a review from Copilot May 20, 2026 11:32

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Copy Markdown
Member

@nilmerg nilmerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might also fix #1326 as a digit doesn't match \w either. Please verify and add a test case.

Comment thread library/Icingadb/Model/CustomvarFlat.php Outdated
Two issues were fixed in the split regex:

1. Special characters before `.` were ignored:
The old regex only split on `.` when directly preceded by a word
character (\w), causing splits to be missed when `.` was preceded
by special characters like whitespace, / or $.
Result before: `foo /.bar.one` => `['foo /.bar', 'one']`
Result after: `foo /.bar.one` => `['foo /', 'bar', 'one']`

2. Brackets mid-word were incorrectly split:
The old regex split before any `[`, causing keys like `con[0]cat` to be
split incorrectly.
Resulti before: `con[0]cat` => `['con', '[0]cat']`
Now splits before `[` only when it's a standalone array index — meaning
`]` is followed by `.`, another `[`, or end of string.
Result after: `con[0]cat` => `['con', '[0]', 'cat']`
@sukhwinder33445 sukhwinder33445 force-pushed the fix/regex-of-preg-split branch from e589b4f to 2aa3a33 Compare May 21, 2026 10:19
@sukhwinder33445
Copy link
Copy Markdown
Contributor Author

This might also fix #1326 as a digit doesn't match \w either. Please verify and add a test case.

\w also matches digits, so the mentioned issue will not be fixed by this PR. I was unable to reproduce it using the custom variables from the linked issue, with or without this PR.

@sukhwinder33445 sukhwinder33445 requested a review from nilmerg May 21, 2026 10:29
@nilmerg nilmerg merged commit 75d4d13 into main May 21, 2026
13 checks passed
@nilmerg nilmerg deleted the fix/regex-of-preg-split branch May 21, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla/signed CLA is signed by all contributors of a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants