Skip to content

Commit

Permalink
Bash: add support for hyphenated param names
Browse files Browse the repository at this point in the history
Previously, a parameter (flag) such as `curl --upload-file` would not be
properly recognized, because of the hyphen in the parameter name. This
commit causes `--upload-file` to be properly recognized as a parameter.

fixes #3569, fixes #3696
  • Loading branch information
reidmv committed Nov 3, 2023
1 parent 59e5a34 commit ac9bba3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/prism-bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
},
// Highlight parameter names as variables
'parameter': {
pattern: /(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:\.\w+)*(?=[=\s]|$)/,
pattern: /(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:[.-]\w+)*(?=[=\s]|$)/,
alias: 'variable',
lookbehind: true
},
Expand Down
2 changes: 1 addition & 1 deletion components/prism-bash.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/languages/bash/parameter_feature.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
docker run
--name elk \
--log-level info \
-p 5601:5601 \
--restart=always \
--privileged \
Expand All @@ -16,6 +17,10 @@ easyj/elk:7.12.1
" elk ",
["punctuation", "\\"],

["parameter", "--log-level"],
" info ",
["punctuation", "\\"],

["parameter", "-p"],
["number", "5601"],
":5601 ",
Expand Down
5 changes: 4 additions & 1 deletion tests/languages/shell-session/issue3047_2.test
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ ssb> ed25519/0x1E7B69B238FFA21B created: 2021-07-21 expires: 2022-07-21
[
["command", [
["shell-symbol", "$"],
["bash", ["gpg --card-status"]]
["bash", [
"gpg ",
["parameter", "--card-status"]
]]
]],
["output", "Reader ...........: Yubico YubiKey CCID\r\nApplication ID ...: D*******************************\r\nApplication type .: OpenPGP\r\nVersion ..........: 0.0\r\nManufacturer .....: Yubico\r\nSerial number ....: 1*******\r\nName of cardholder: John Doe\r\nLanguage prefs ...: en\r\nSalutation .......:\r\nURL of public key : [not set]\r\nLogin data .......: john@example.net\r\nSignature PIN ....: not forced\r\nKey attributes ...: ed25519 cv25519 ed25519\r\nMax. PIN lengths .: 127 127 127\r\nPIN retry counter : 3 0 3\r\nSignature counter : 0\r\nKDF setting ......: off\r\nUIF setting ......: Sign=on Decrypt=on Auth=on\r\nSignature key ....: ACE1 3F15 90C1 A8C9 D942 51E3 02ED C61B 6543 509B\r\n created ....: 2021-07-21 18:44:34\r\nEncryption key....: 0524 00F4 8E1D 085A F3E1 61EC D463 4E0D 6E2D D8BF\r\n created ....: 2021-07-21 18:44:52\r\nAuthentication key: A27B 582F 1F62 03BA 549B 3D44 1E7B 69B2 38FF A21B\r\n created ....: 2021-07-21 18:45:13\r\nGeneral key info..: sub ed25519/0x02EDC61B6543509B 2021-07-21 John Doe <john@example.net>\r\nsec# ed25519/0xC2709D13BAB4763C created: 2021-07-21 expires: never\r\nssb> ed25519/0x02EDC61B6543509B created: 2021-07-21 expires: 2022-07-21\r\n card-no: 0006 1*******\r\nssb> cv25519/0xD4634E0D6E2DD8BF created: 2021-07-21 expires: 2022-07-21\r\n card-no: 0006 1*******\r\nssb> ed25519/0x1E7B69B238FFA21B created: 2021-07-21 expires: 2022-07-21\r\n card-no: 0006 1*******"]
]

0 comments on commit ac9bba3

Please sign in to comment.