-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix BUG_BRACQUOT: quoting in glob bracket expression ineffective
Example reproducers: case b in ( ['a-c'] ) echo BUG ;; esac Output: BUG, expected: none. touch b && echo ["a-c"] Output: b; expected: [a-c] In both reproducers, the - character in the bracket expression is part of a quoted string, which should cause the shell to escape it, disabling its processing as a range opereator. Previous discussion that explains why this is a bug: https://www.mail-archive.com/[email protected]/msg02036.html Analysis: The 'case' execution code (case TSW: in sh_exec()) calls sh_macpat() (macro.c) to parse the pattern, which calls copyto(), which (among many other things) translates single and double shell quotes into corresponding backslash escapes where needed. These backslash escapes are internally understood by the regex parser. But in a bracket pattern like ["!"a"-"c], neither the quoted "!" nor the quoted "-" get such an internal backslash after quote removal. This is the bug. copyto() is effectively a lexer for expansions. It uses the ST_DOL lexical state table a.k.a. sh_lexstate6[]. Adding a new lexical state for !, ^ and -, ST_BRAOP, allows copyto() to keep track of bracket expressions in glob patterns and add those escapes. src/cmd/ksh93/include/lexstates.h, src/cmd/ksh93/data/lexstates.c: - Define new S_BRAOP state for bracket expression operator (!^-). We can re-use the value of S_RES (4) as it's unused in ST_DOL. src/cmd/ksh93/sh/macro.c: copyto(): - S_BRACT, S_ENDCH: Keep track of bracket expressions with a 'bracketexpr' flag that is only set if we're processing a pattern that is not an ERE (only the glob pattern behaviour should be changed). - S_ESC: Preserve any existing backslash if bracketexpr is set and the current character is an S_BRAOP character. This fixes the bug for bracket expressions like [\!N] and [\^N] (where the escaped ! and ^ should not be negators). - S_BRAOP: Added. Write a backslash (ESCAPE) on the stack if bracketexpr is set and the current character (a bracket expression operator) is double or single quoted. This fixes the rest of the bug. Resolves: #488
- Loading branch information
Showing
8 changed files
with
122 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters