Domino web pre-processing - strange behaviour?
I've been customising Ben Poole's dominoWiki to suit our internal needs (adding things like page renaming and disambiguation for example). So far so good.
As users add more varied content and experiment with the syntax we discover the odd strange anomaly. Here's an example:
The user adds some content to a wiki page like this:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
1234567890
,./;'<>?:@[]{}!"£$%^&*()_-+=
[
]
[ ]
A [ ]
and when saved the render output looks like this:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
1234567890
,./;'<>?:@[]{}!"£$%^&*()_-+=
]
[ ]
A [ ]
If you look carefully you'll see the " [" after the "-+=" and newline disapears!
You could test this yourself by creating a form in a database with a single rich text field called "Body". Create a WebQueryOpen agent with the following code & have the form run the agent when the document is opened on the web.
Sub Initialize
Dim session As New NotesSession
Dim content As String
Dim doc As NotesDocument
Dim niBody As NotesItem
Set doc = session.DocumentContext
Set niBody = doc.ReplaceItemValue("Body","")
content=" ABCDEFGHIJKLMNOPQRSTUVWXYZ"
content= content + Chr$(10) + " abcdefghijklmnopqrstuvwxyz"
content= content + Chr$(10) + " 1234567890"
content = content + Chr$(10) + { ,./;'<>?:@[]}+ "{}" +{!"£$%^&*()_-+=}
content= content + Chr$(10) + " *[*"
content= content + Chr$(10) + " ]"
content= content + Chr$(10) + "["
content= content + Chr$(10) + "]"
content= content + Chr$(10) + "[ ]"
content= content + Chr$(10) + "A [ ]"
content = massageChunk(content, True)
Set niBody = doc.ReplaceItemValue("Body",content)
End Sub
Private Function massageChunk(txt As String, noParaTag As Boolean) As String
If noParaTag Then
massageChunk = Replace(txt, Chr(10) & Chr(10), "<br />")
massageChunk = Replace(massageChunk, Chr(10), "<br />")
Else
massageChunk = Replace(txt, Chr(10) & Chr(10), "<p>")
massageChunk = Replace(massageChunk, Chr(10), "<br />")
End If
massageChunk = Replace(txt, Chr(10) & Chr(10), "<p>")
massageChunk = Replace(massageChunk, Chr(10), "<br>")
'** special case where </h3><br> adds too much line spacing
massageChunk = Replace(massageChunk, "</h3><br>", "</h3>")
massageChunk = Replace(massageChunk, "</h4><br>", "</h4>")
massageChunk = Replace(massageChunk, "<br><li>", "<li>")
massageChunk = Replace(massageChunk, "</li><br>", "</li>")
massageChunk = Replace(massageChunk, "</ol><br>", "</ol>")
massageChunk = Replace(massageChunk, "</ul><br>", "</ul>")
massageChunk = Replace(massageChunk, "<br><dl>", "<dl>")
massageChunk = Replace(massageChunk, "<br><dt>", "<dt>")
massageChunk = Replace(massageChunk, "<br><dd>", "<dd>")
massageChunk = Replace(massageChunk, "</dl><br>", "</dl>")
massageChunk = Replace(massageChunk, "</dt><br>", "</dt>")
massageChunk = Replace(massageChunk, "</dd><br>", "</dd>")
End Function
When you open the form on the web you should see the problem. Now edit the agent so that line
content= content + Chr$(10) + " [" becomes content= content + Chr$(10) + " *[*" and you'll see that the *[* appears in the ouput where the "[" character had been dropped.
I'm guessing that it has something to do with Domino pre-processing content for the web and thinking that opening bracket denotes pass through HTML. That said why isn't the corresponding "]" also dropped along with subsequent "[" "]" pairings?
It's clear to me (through testing) that the Replace function isn't at fault.
Does this make any sense? Am I missing something?
Jason
(p.s. I have another anomaly up my sleeve for later today if I get time
)
As users add more varied content and experiment with the syntax we discover the odd strange anomaly. Here's an example:
The user adds some content to a wiki page like this:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
1234567890
,./;'<>?:@[]{}!"£$%^&*()_-+=
[
]
[ ]
A [ ]
and when saved the render output looks like this:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
1234567890
,./;'<>?:@[]{}!"£$%^&*()_-+=
]
[ ]
A [ ]
If you look carefully you'll see the " [" after the "-+=" and newline disapears!
You could test this yourself by creating a form in a database with a single rich text field called "Body". Create a WebQueryOpen agent with the following code & have the form run the agent when the document is opened on the web.
Sub Initialize
Dim session As New NotesSession
Dim content As String
Dim doc As NotesDocument
Dim niBody As NotesItem
Set doc = session.DocumentContext
Set niBody = doc.ReplaceItemValue("Body","")
content=" ABCDEFGHIJKLMNOPQRSTUVWXYZ"
content= content + Chr$(10) + " abcdefghijklmnopqrstuvwxyz"
content= content + Chr$(10) + " 1234567890"
content = content + Chr$(10) + { ,./;'<>?:@[]}+ "{}" +{!"£$%^&*()_-+=}
content= content + Chr$(10) + " *[*"
content= content + Chr$(10) + " ]"
content= content + Chr$(10) + "["
content= content + Chr$(10) + "]"
content= content + Chr$(10) + "[ ]"
content= content + Chr$(10) + "A [ ]"
content = massageChunk(content, True)
Set niBody = doc.ReplaceItemValue("Body",content)
End Sub
Private Function massageChunk(txt As String, noParaTag As Boolean) As String
If noParaTag Then
massageChunk = Replace(txt, Chr(10) & Chr(10), "<br />")
massageChunk = Replace(massageChunk, Chr(10), "<br />")
Else
massageChunk = Replace(txt, Chr(10) & Chr(10), "<p>")
massageChunk = Replace(massageChunk, Chr(10), "<br />")
End If
massageChunk = Replace(txt, Chr(10) & Chr(10), "<p>")
massageChunk = Replace(massageChunk, Chr(10), "<br>")
'** special case where </h3><br> adds too much line spacing
massageChunk = Replace(massageChunk, "</h3><br>", "</h3>")
massageChunk = Replace(massageChunk, "</h4><br>", "</h4>")
massageChunk = Replace(massageChunk, "<br><li>", "<li>")
massageChunk = Replace(massageChunk, "</li><br>", "</li>")
massageChunk = Replace(massageChunk, "</ol><br>", "</ol>")
massageChunk = Replace(massageChunk, "</ul><br>", "</ul>")
massageChunk = Replace(massageChunk, "<br><dl>", "<dl>")
massageChunk = Replace(massageChunk, "<br><dt>", "<dt>")
massageChunk = Replace(massageChunk, "<br><dd>", "<dd>")
massageChunk = Replace(massageChunk, "</dl><br>", "</dl>")
massageChunk = Replace(massageChunk, "</dt><br>", "</dt>")
massageChunk = Replace(massageChunk, "</dd><br>", "</dd>")
End Function
When you open the form on the web you should see the problem. Now edit the agent so that line
content= content + Chr$(10) + " [" becomes content= content + Chr$(10) + " *[*" and you'll see that the *[* appears in the ouput where the "[" character had been dropped.
I'm guessing that it has something to do with Domino pre-processing content for the web and thinking that opening bracket denotes pass through HTML. That said why isn't the corresponding "]" also dropped along with subsequent "[" "]" pairings?
It's clear to me (through testing) that the Replace function isn't at fault.
Does this make any sense? Am I missing something?
Jason
(p.s. I have another anomaly up my sleeve for later today if I get time


Comments