Patterns: Add Controls and Windream Modules
This commit is contained in:
@@ -3,9 +3,11 @@ Imports System.Text.RegularExpressions
|
||||
|
||||
Namespace [PatternModule]
|
||||
Public Class BaseModule
|
||||
Friend ReadOnly Logger As Logger
|
||||
|
||||
Private ReadOnly Logger As Logger
|
||||
Private ReadOnly MyRegex As Regex = New Regex("{#(\w+)#([\:\.\w\s_-]+)}+")
|
||||
Private ReadOnly SqlPhrases As New List(Of String) From {
|
||||
"SELECT ", "UPDATE ", "DELETE ", "EXEC "
|
||||
}
|
||||
|
||||
Private Const MAX_TRY_COUNT = 500
|
||||
|
||||
@@ -21,23 +23,37 @@ Namespace [PatternModule]
|
||||
pCounter += 1
|
||||
End Sub
|
||||
|
||||
Public Function ReplacePattern(input As String, type As String, replacement As String) As String
|
||||
Dim elements As MatchCollection = MyRegex.Matches(input)
|
||||
Public Function ReplacePattern(pInput As String, pType As String, pReplacement As String) As String
|
||||
Dim oElements As MatchCollection = MyRegex.Matches(pInput)
|
||||
|
||||
If IsNothing(replacement) Then
|
||||
Return input
|
||||
If IsNothing(pReplacement) Then
|
||||
Return pInput
|
||||
End If
|
||||
|
||||
For Each element As Match In elements
|
||||
Dim oIsSQL As Boolean = False
|
||||
For Each oPhrase In SqlPhrases
|
||||
If pInput.Contains(oPhrase) Then
|
||||
oIsSQL = True
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
If oIsSQL = True Then
|
||||
Logger.Debug("Input string is most likely an SQL Query, masking quotes in replacement string.")
|
||||
pReplacement = pReplacement.Replace("'", "''")
|
||||
End If
|
||||
|
||||
For Each oElement As Match In oElements
|
||||
' if group 1 contains the 'pattern' the replace whole group with 'replacement'
|
||||
' and return it
|
||||
If element.Groups(1).Value = type Then
|
||||
Return Regex.Replace(input, element.Groups(0).Value, replacement)
|
||||
If oElement.Groups(1).Value = pType Then
|
||||
Logger.Debug("Replacing Placeholder with [{0}]", pReplacement)
|
||||
Return Regex.Replace(pInput, oElement.Groups(0).Value, pReplacement)
|
||||
End If
|
||||
Next
|
||||
|
||||
' no replacement made
|
||||
Return input
|
||||
Return pInput
|
||||
End Function
|
||||
|
||||
Public Function ContainsPatternAndValue(pInput As String, pType As String, pValue As String) As Boolean
|
||||
@@ -45,10 +61,10 @@ Namespace [PatternModule]
|
||||
|
||||
For Each oElement As Match In oElements
|
||||
' Pattern in pInput
|
||||
Dim t As String = oElement.Groups(1).Value
|
||||
Dim v As String = oElement.Groups(2).Value
|
||||
Dim oType As String = oElement.Groups(1).Value
|
||||
Dim oValue As String = oElement.Groups(2).Value
|
||||
|
||||
If t = pType And v = pValue Then
|
||||
If oType = pType And oValue = pValue Then
|
||||
Return True
|
||||
End If
|
||||
Next
|
||||
@@ -84,16 +100,16 @@ Namespace [PatternModule]
|
||||
Return False
|
||||
End Function
|
||||
|
||||
Public Function GetNextPattern(input As String, type As String) As Pattern
|
||||
Dim elements As MatchCollection = MyRegex.Matches(input)
|
||||
Public Function GetNextPattern(pInput As String, pType As String) As Pattern
|
||||
Dim oElements As MatchCollection = MyRegex.Matches(pInput)
|
||||
|
||||
For Each element As Match In elements
|
||||
For Each oElement As Match In oElements
|
||||
' Pattern in pInput
|
||||
Dim t As String = element.Groups(1).Value
|
||||
Dim v As String = element.Groups(2).Value
|
||||
Dim oType As String = oElement.Groups(1).Value
|
||||
Dim oValue As String = oElement.Groups(2).Value
|
||||
|
||||
If t = type Then
|
||||
Return New Pattern(t, v)
|
||||
If oType = pType Then
|
||||
Return New Pattern(oType, oValue)
|
||||
End If
|
||||
Next
|
||||
|
||||
|
||||
Reference in New Issue
Block a user