Ingen, det är ju ett par anändare på forumet som uppenbarligen använt sig av denna klass. Har sök men inte hittat lösning på just detta problemet. Har ingen av er som använt klassen stött på mitt problem?
Skillnaden var att här fungerade det inte att göra autopostback från en listbox pga att filtret plockade bort "name" attributet från listboxen, filtret som finns i denna tråd, löste dock problemet.
Public Class XHTMLStrictFilter
Inherits Stream
Private _sink As Stream
Private _position As Long
Private Shared _regForm As New Regex("<form .*name=.* .*>", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
Private Shared _regNameReplace As New Regex("name=[^ ]*", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
Private Shared _regViewState As New Regex("<input type=""hidden"" name=""__VIEWSTATE"" value="".*"" />", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
' Tillagd 2004-02-11. Tar bort alla border="0"
Private Shared _regBorder As New Regex("border=[^ ]*", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
' Tillagd 2004-03-03. Byter language="javascript" till type="text/javascript"
Private Shared _regType As New Regex("language=""javascript""", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
' Tillagd 2004-03-03. fixar namnet på formuläret.
Private Shared _regForm1 As New Regex("document.Form1", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
Private _formFix As Boolean
Private _viewStateFix As Boolean
Private _borderFix As Boolean
Private _typeFix As Boolean
Private _form1Fix As Boolean
Public Sub New(ByVal sink As Stream)
_sink = sink
End Sub 'New
' The following members of Stream must be overriden.
Public Overrides ReadOnly Property CanRead() As Boolean
Get
Return True
End Get
End Property
Public Overrides ReadOnly Property CanSeek() As Boolean
Get
Return True
End Get
End Property
Public Overrides ReadOnly Property CanWrite() As Boolean
Get
Return True
End Get
End Property
Public Overrides ReadOnly Property Length() As Long
Get
Return 0
End Get
End Property
Public Overrides Property Position() As Long
Get
Return _position
End Get
Set(ByVal Value As Long)
_position = value
End Set
End Property
Public Overrides Function Seek(ByVal offset As Long, ByVal direction As System.IO.SeekOrigin) As Long
Return _sink.Seek(offset, direction)
End Function 'Seek
Public Overrides Sub SetLength(ByVal length As Long)
_sink.SetLength(length)
End Sub 'SetLength
Public Overrides Sub Close()
_sink.Close()
End Sub 'Close
Public Overrides Sub Flush()
_sink.Flush()
End Sub 'Flush
Public Overrides Function Read(ByVal buffer() As Byte, ByVal offset As Integer, ByVal count As Integer) As Integer
Return _sink.Read(buffer, offset, count)
End Function 'Read
' The Write method actually does the filtering.
Public Overrides Sub Write(ByVal buffer() As Byte, ByVal offset As Integer, ByVal count As Integer)
Dim data() As Byte
If Not _formFix Or Not _viewStateFix Or Not _borderFix Or Not Me._typeFix Or Not Me._form1Fix Then
'string htmlOutput = System.Text.UTF8Encoding.UTF8.GetString(buffer);
Dim htmlOutput As String = System.Text.Encoding.GetEncoding("iso-8859-1").GetString(buffer)
Dim length As Integer = htmlOutput.Length
If Not _formFix And _regForm.IsMatch(htmlOutput) Then
Dim formMatch As String = _regForm.Match(htmlOutput).Value
' *** Borttagen 03-06-17 ***
' *** htmlOutput=Regex.Replace(htmlOutput, formMatch, _regNameReplace.Replace(formMatch, ""), RegexOptions.IgnoreCase);
htmlOutput = Regex.Replace(htmlOutput, _regNameReplace.Match(formMatch).Value, "", RegexOptions.IgnoreCase)
_formFix = True
End If
If Not _viewStateFix And _regViewState.IsMatch(htmlOutput) Then
Dim viewStateMatch As String = _regViewState.Match(htmlOutput).Value
htmlOutput = Regex.Replace(htmlOutput, "<input type=""hidden"" name=""__VIEWSTATE"" value="".*"" />", "<div>" + viewStateMatch + "</div>", RegexOptions.IgnoreCase)
_viewStateFix = True
End If
' Tillagd 2004-02-11. Tar bort alla border="0"
If Not _borderFix And _regBorder.IsMatch(htmlOutput) Then
Dim formMatch As String = _regBorder.Match(htmlOutput).Value
htmlOutput = Regex.Replace(htmlOutput, _regBorder.Match(formMatch).Value, "", RegexOptions.IgnoreCase)
_borderFix = True
End If
If Not Me._typeFix And _regType.IsMatch(htmlOutput) Then
Dim formMatch As String = _regType.Match(htmlOutput).Value
htmlOutput = Regex.Replace(htmlOutput, _regType.Match(formMatch).Value, "type=""text/javascript""", RegexOptions.IgnoreCase)
Me._typeFix = True
End If
If Not Me._form1Fix And _regForm1.IsMatch(htmlOutput) Then
Dim formMatch As String = _regForm1.Match(htmlOutput).Value
htmlOutput = Regex.Replace(htmlOutput, _regForm1.Match(formMatch).Value, "document.forms[0]", RegexOptions.IgnoreCase)
Me._form1Fix = True
End If
'data = System.Text.UTF8Encoding.UTF8.GetBytes(htmlOutput);
data = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(htmlOutput)
count -= length - htmlOutput.Length
Else
data = New Byte(count) {}
'Buffer.BlockCopy(buffer, offset, data, 0, count)
End If
_sink.Write(data, 0, count)
End Sub 'Write
End Class 'XHTMLStrictFilter