Skip to content

Fix Bash function list missing functions after a bare "#" comment line - #18527

Open
haraldrohan wants to merge 1 commit into
notepad-plus-plus:masterfrom
haraldrohan:fix_bash_functionlist_comment_20261020
Open

haraldrohan wants to merge 1 commit into
notepad-plus-plus:masterfrom
haraldrohan:fix_bash_functionlist_comment_20261020

Conversation

@haraldrohan

Copy link
Copy Markdown
Contributor

Summary

Fixes #18174.

In the Bash function-list parser (PowerEditor/installer/functionList/bash.xml), the single-line comment part of commentExpr is:

(?-s:(?:^\x23[^!]|^\h*\x23|\h+\x23).*$)

On a line containing only #, [^!] (meant to exclude a #! shebang) matches the line break, so .*$ swallows the next line. If that line is a function header, the function is missing from the Function List:

#
# exit with error message
#
errorExit()     # <- swallowed by the comment on the line above, not listed
{
	exit 5
}

This only happens with LF line endings (typical for shell scripts). With CRLF, [^!] consumes the \r and the \n stays intact, so the function is found.

Fix

Replaced [^!] with the zero-width negative lookahead (?!!), which still rejects #! but does not consume any character. No other part of the expression changes.

Test plan

  • Extended PowerEditor/Test/FunctionList/bash/unitTest with a function preceded by a bare-# comment block; updated unitTest.expected.result.
  • Full Function List test harness (unitTestLauncher.ps1): all 46 tests pass.
  • notepad++.exe -export=functionList -lbash on the LF example from the issue: errorExit is now listed (before: nothing).

Note: with core.autocrlf=true (as in CI) the test file is checked out with CRLF, where this bug doesn't occur, so the new test case documents the scenario rather than guarding against regressions.

🤖 Generated with Claude Code

In the Bash parser's commentExpr, "^\x23[^!]" (meant to exclude a "#!"
shebang) let "[^!]" consume the line break of a line that contains only
"#", so the following ".*$" swallowed the whole next line - e.g. the
function header - as part of the comment. This only happens with LF line
endings; with CRLF, "[^!]" consumes the "\r" instead.

Replaced "[^!]" with the zero-width lookahead "(?!!)", and extended the
bash unit test with a function preceded by such a comment block.

Fix notepad-plus-plus#18174

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bash function list extraction fails when certain comments are in front of the function

2 participants