Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.0.0] Only escape standard BRE metacharacters when preparing grep p…
…attern. (#20118) POSIX specifies1 that grep shall by default interpret patterns as Basic Regular Expressions2. BREs only have six metacharacters: .[\*^$; all other characters are interpreted literally. Escaping non-metacharacter characters (ordinary characters) either has the effect of turning them into metacharacters3, or the interpretation is left undefined by the spec. Because of the potential for unintended interpretations and behaviours, escaping these ordinary characters before using them in a BRE is undesirable. Unintended behaviours may range from benign (e.g. warnings about the invalid escapes) to broken (not matching entries we did intend and/or matching entries we did not intend). Punctuation characters incorrectly escaped by the prior implementation can come from a few different places: The ~ used by Bzlmod to manage hierarchies. From the path to the workspace root - caller path may be absolute. From paths within the workspace - punctuation characters accepted by Bazel4 for package and target names but are ordinary characters in BREs include !%@"#&'()-+,;<=>?]{|}~. A small demonstration of this unnecessary escaping is available at: https://github.com/plobsing/bzlmod-bash-runfiles-grep-warning-demo/tree/main In the example, the unnecessary escaping is reported when the script runs the rlocation function: grep: warning: stray \ before ~ grep: warning: stray \ before @ Closes #20066. Commit 8c70d7b PiperOrigin-RevId: 580820470 Change-Id: I57218d629cc771a00f05c2da06e97fb0b2ca18fd Co-authored-by: Peter Lobsinger <plobsing@gmail.com>
- Loading branch information