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

When suggesting KA/RO escape regex #473

Merged
merged 1 commit into from
Sep 3, 2023
Merged

Conversation

AdhocAdam
Copy link
Owner

@AdhocAdam AdhocAdam commented Aug 23, 2023

Discovered an issue wherein if:

  • Email is sent to the connector
  • The email contains one or many signature graphics
  • The signature graphic(s) have alt text defined

The suggestions for that particular email will never return any results. This is due to the conversion from inline images to text that can be written into SCSM. Take the following an example, an email has a:

  • Subject of "mobile issue"
  • Body of "screen crack"
  • Has a signature graphic with alt text of "corporate signature." If you right click on the message preview in Outlook, choose "View Source", then scroll down to find the inline image it will render something to the effect of:
<img width=233 height=167 style='width:2.427in;height:1.7395in' id="Picture_x0020_1" src="cid:image001.jpg@01D9D51B.5DC75C80" alt="corporate signature">

But when this email is processed by the connector, the alt text property from the above is read and written into the new Work Item Description as:

screen crack

[corporate signature]

When either Search-CiresonKnowledgeBase or Search-AvailablePortalOffering functions engage, an error will be produced to the effect of:

System.ArgumentException: parsing "\b[corporate\b" - Unterminated [] set.
   at System.Text.RegularExpressions.RegexParser.ScanCharClass(Boolean caseInsensitive, Boolean scanOnly)
   at System.Text.RegularExpressions.RegexParser.CountCaptures()
   at System.Text.RegularExpressions.RegexParser.Parse(String re, RegexOptions op)
   at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, TimeSpan matchTimeout, Boolean useCache)
   at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options)
   at System.Management.Automation.ParserOps.NewRegex(String patternString, RegexOptions options)
   at System.Management.Automation.ParserOps.MatchOperator(ExecutionContext context, IScriptExtent errorPosition, Object lval, Object rval, Boolean notMatch, Boolean ignoreCase)
   at System.Management.Automation.Interpreter.FuncCallInstruction`7.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

This is due to the the following lines seen in Search-CiresonKnowledgeBase and Search-AvailableCiresonPortalOffering functions:

$wordsMatched = ($searchQuery.Trim().Split() | Where-Object{($kbResult.title -match "\b$_\b")}).count
$wordsMatched = ($searchQuery.Trim().Split() | Where-Object{($serviceCatalogResult.RequestOfferingTitle -match "\b$_\b") -or ($serviceCatalogResult.RequestOfferingDescription -match "\b$_\b")}).count

When this engages, the first result (from the $searchQuery.Trim().Split()) passed down the pipeline looks like:

phone
issue
screen
crack
[corporate
signature]

By introducing a Foreach-Object on the pipeline that escapes relevant characters (known as a result of #453):

$wordsMatched = ($searchQuery.Trim().Split() | ForEach-Object {[regex]::Escape($_)} | Where-Object{($kbResult.title -match "\b$_\b")}).count
$wordsMatched = ($searchQuery.Trim().Split() | ForEach-Object {[regex]::Escape($_)} | Where-Object{($serviceCatalogResult.RequestOfferingTitle -match "\b$_\b") -or ($serviceCatalogResult.RequestOfferingDescription -match "\b$_\b")}).count

the result now looks like:

phone
issue
screen
crack
\[corporate
signature]

And the email will successfully trigger KA and/or RO suggestion URLs

in the event the email subject/body contain regex patterns, this will ensure they are escaped correctly
@AdhocAdam AdhocAdam added this to the 5.0.4 milestone Aug 23, 2023
@AdhocAdam AdhocAdam self-assigned this Aug 23, 2023
@AdhocAdam AdhocAdam marked this pull request as ready for review September 3, 2023 17:22
@AdhocAdam AdhocAdam merged commit b8d8fc8 into dev-5.x Sep 3, 2023
1 check passed
AdhocAdam added a commit that referenced this pull request Sep 10, 2023
* Allow plus addressing in Multi Inbox (#464)

Extends regex pattern support on MultipleMailboxes.xaml

* Remove "Resolved By User" Relationship when WorkItem is reactivated (#467)

* Update smletsExchangeConnector.ps1

* Update smletsExchangeConnector.ps1

* Remove-SCSMRelationshipObject one liner

After testing it does not appear there is a scenario wherein the try/catch will engage.

---------

Co-authored-by: Adam <adhocadam@protonmail.com>

* logging, cireson integration (#469)

Introduce logging events for functions that are responsible for obtaining suggestion URLs (KB/RO) from one's Cireson portal

* escape potential regex (#473)

in the event the Suggestions are enabled and the email subject/body contain regex patterns, this will ensure they are escaped correctly

* update version notes and contributors (#474)

* version notes

update inline notes and contributors

* contributors

updating contributors per release

---------

Co-authored-by: Konstantin Slavin-Borovskij <betalyte@gmail.com>
Co-authored-by: SimonZein <128088337+SimonZein@users.noreply.github.com>
@AdhocAdam AdhocAdam deleted the dev-5.x-SuggestionsRegex branch September 10, 2023 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant