Closed Windos closed 6 years ago
Would using [regex]::escape()
be easier here so we don't need to maintain that list of special characters? We can just make it $prefix = [regex]::escape($prefix)
and that should be all needed.
From: Joshua King notifications@github.com Sent: Thursday, October 11, 2018 1:53:57 AM To: poshbotio/PoshBot Cc: Subscribed Subject: [poshbotio/PoshBot] Adding array of special character, and escaping them (#125)
Description
Adding array of special character, and escaping them
Basically, some characters are regex special characters... '.' is a wildcard... so it was matching on literally everything. Adding an escape character (only when it's needed) allows the match to be literal.
Related Issue
This should fix issue #124https://github.com/poshbotio/PoshBot/issues/124.
Motivation and Context
Allows using desired prefix characters, such as .
. about
How Has This Been Tested?
Tested using standard (!) prefixes, and indicated issue prefix (.), and other random ones (a)
Also tested to ensure that string prefixes (bender) still work
Screenshots (if appropriate):
Testing with ! prefix
[test-]https://user-images.githubusercontent.com/6955786/46773852-0c30a500-cd5c-11e8-98d5-3efa1ac0671f.PNG
Testing with . prefix
[test-period]https://user-images.githubusercontent.com/6955786/46773863-12bf1c80-cd5c-11e8-81bb-8cac370a47ae.PNG
Types of changes
Checklist:
You can view, comment on, or merge this pull request online at:
https://github.com/poshbotio/PoshBot/pull/125
Commit Summary
File Changes
Patch Links:
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/poshbotio/PoshBot/pull/125, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AQDqFrG1pdhIeyowjmonxiNIx3hkXc2gks5ujpalgaJpZM4XWlPU.
Ooooh, yes. I had originally tried:
if ($parsedCommand.command -match [regex]::escape("^$prefix")) {
But of course that escaped the carrot. I'll give it a shot.
Don't merge, just realised I missed something
Sorted.
Awesome. Using [regex]::escape()
is nice and clean!
Description
Adding array of special character, and escaping them
Basically, some characters are regex special characters... '.' is a wildcard... so it was matching on literally everything. Adding an escape character (only when it's needed) allows the match to be literal.
Related Issue
This should fix issue #124.
Motivation and Context
Allows using desired prefix characters, such as .
. about
How Has This Been Tested?
Tested using standard (!) prefixes, and indicated issue prefix (.), and other random ones (a)
Also tested to ensure that string prefixes (bender) still work
Screenshots (if appropriate):
Testing with ! prefix
Testing with . prefix
Types of changes
Checklist: