Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bash] Don't nest ${} parameter expansion on { #216

Closed
zufuliu opened this issue Dec 3, 2023 · 1 comment
Closed

[Bash] Don't nest ${} parameter expansion on { #216

zufuliu opened this issue Dec 3, 2023 · 1 comment
Labels
bash Caused by the bash lexer committed Issue fixed in repository but not in release

Comments

@zufuliu
Copy link
Contributor

zufuliu commented Dec 3, 2023

https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion

When braces are used, the matching ending brace is the first ‘}’ not escaped by a backslash or within a quoted string, and not within an embedded arithmetic expansion, command substitution, or parameter expansion.

following code (from __parse_options() inside msys2's usr\share\bash-completion\bash_completion script) is messed by incorrect nesting:

# Expand --[no]foo to --foo and --nofoo etc
if [[ $option =~ (\[((no|dont)-?)\]). ]]; then
    option2=${option/"${BASH_REMATCH[1]}"/}
    option2=${option2%%[<{().[]*}
    printf '%s\n' "${option2/=*/=}"
    option=${option/"${BASH_REMATCH[1]}"/"${BASH_REMATCH[2]}"}
fi

option=${option%%[<{().[]*}
printf '%s\n' "${option/=*/=}"
zufuliu added a commit to zufuliu/notepad4 that referenced this issue Dec 3, 2023
@zufuliu
Copy link
Contributor Author

zufuliu commented Dec 3, 2023

Patch to fix the bug: 216.patch

@@ -935,7 +935,9 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
 						continue;
 					}
 				} else if (sc.ch == QuoteStack.Current.Up) {
-					QuoteStack.Current.Count++;
+					if (QuoteStack.Current.Style != QuoteStyle::Parameter) {
+						QuoteStack.Current.Count++;
+					}
 				} else {
 					if (QuoteStack.Current.Style == QuoteStyle::String ||
 						QuoteStack.Current.Style == QuoteStyle::HereDoc ||
option="no[foo]"
option=${option%%[<{().[]*}
echo $option

replacing second { with } inside option=${option%%[<{().[]*} causes syntax errors, so there is no need to detect regex pattern range.

@nyamatongwe nyamatongwe added the bash Caused by the bash lexer label Dec 4, 2023
@nyamatongwe nyamatongwe added the committed Issue fixed in repository but not in release label Dec 4, 2023
donho pushed a commit to notepad-plus-plus/notepad-plus-plus that referenced this issue Dec 26, 2023
Scintilla 5.4.1
https://www.scintilla.org/scintilla541.zip
Released 27 December 2023.

1.  Add IDocumentEditable interface to allow efficient interaction with document objects which may not be visible in a Scintilla instance. This feature is provisonal and may change before being declared stable. For better type-safety, the ScintillaCall C++ API uses IDocumentEditable* where void* was used before which may require changes to client code that uses document pointer APIs DocPointer, SetDocPointer, CreateDocument, AddRefDocument, and ReleaseDocument.
2.  Ctrl-click on a selection deselects it in multiple selection mode.
3.  Add SCI_SELECTIONFROMPOINT for modifying multiple selections.
4.  Add SCI_SETMOVEEXTENDSSELECTION and SCI_CHANGESELECTIONMODE to simplify selection mode manipulation.
5.  Improve performance of global replace by reducing cache invalidation overhead. [Feature #1502](https://sourceforge.net/p/scintilla/feature-requests/1502/).
6.  Fix regular expression search for "\<" matching beginning of search when not beginning of word and for "\>" not matching line end. [Bug #2157](https://sourceforge.net/p/scintilla/bugs/2157/).
7.  Fix regular expression search failure when search for "\<" followed by search for "\>". [Bug #2413](https://sourceforge.net/p/scintilla/bugs/2413/).
8.  Fix regular expression assertion (^, $, \b. \B) failures when using SCFIND_CXX11REGEX. [Bug #2405](https://sourceforge.net/p/scintilla/bugs/2405/).
9.  Fix regular expression bug in reverse direction where shortened match returned. [Bug #2405](https://sourceforge.net/p/scintilla/bugs/2405/).
10. Avoid character fragments in regular expression search results. [Bug #2405](https://sourceforge.net/p/scintilla/bugs/2405/).
11. With a document that does not have the SC_DOCUMENTOPTION_TEXT_LARGE option set, allocating more than 2G (calling SCI_ALLOCATE or similar) will now fail with SC_STATUS_FAILURE.
12. Protect SCI_REPLACETARGET, SCI_REPLACETARGETMINIMAL, and SCI_REPLACETARGETRE from application changing target in notification handlers. [Bug #2289](https://sourceforge.net/p/scintilla/bugs/2289/).

Lexilla 5.3.0
https://www.scintilla.org/lexilla530.zip
Released 27 December 2023.

1. Fix calling AddStaticLexerModule by defining as C++ instead of C which matches header. [Bug #2421](https://sourceforge.net/p/scintilla/bugs/2421/).
2. Bash: Fix shift operator << incorrectly recognized as here-doc. [Issue #215](ScintillaOrg/lexilla#215).
3. Bash: Fix termination of '${' with first unquoted '}' instead of nesting. [Issue #216](ScintillaOrg/lexilla#216).
4. HTML: JavaScript double-quoted strings may escape line end with '\'. [Issue #214](ScintillaOrg/lexilla#214).
5. Lua: recognize --- doc comments. Defined by [LDoc](https://github.com/lunarmodules/ldoc). Does not recognize --[[-- doc comments which seem less common.

Close #14375
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bash Caused by the bash lexer committed Issue fixed in repository but not in release
Projects
None yet
Development

No branches or pull requests

2 participants