Escaping

By

OpenWebStudio is a tag based language, which provides the ability for each tag value to contain multiple attribute values. OpenWebStudio tags are enclosed with either Brackets or Curly Braces ([,{.}.]) and may contain tags within tags. The result of this, at times, is the desire to either ignore tags within conditions which will not be displayed, and therefore should not be rendered or executed unless the condition were to pass. Another possible reason, and more common, is when the inner tag, or inner content contains a symbol (like the Bracket or Curly Brace, or more frequently, a double quote) which will cause the tag to fail to render properly, because the characters cause the format of the tag to be invalid.

Whenever any of these conditions apply, you can simply avoid the ill behaviour by escaping the content which invalidates your statement. This is done quite easily. Take the syntax which you would like to avoid rendering, and escape the contained symbols which will cause the invalid statement.

For example:
The most frequent cause of invalid statements, or broken OpenWebStudio tags is the existence of an ACTION tag, which results in an href=”…” value to be rendered, contained within a bounding IIF tag.

{IIF,”[frmMyValue,Form]=1”,”<a {ACTION,”Save”,”Toolbar”,,M}>Save</a>”,”Incomplete.”}

It is important to note here, that OpenWebStudio renders from the inside out, meaning that – since it must handle appropriate conversion, it must essentially render the inner-most tags before it renders the bounding tags. This means that the previous structure will first render the {ACTION… prior to the rendering of the IIF, which will cause a very bad problem:

{IIF,”1=1”,”<a href=”__doPostBack(…);”>Save</a>”,”Incomplete.”}

Obviously this is not good for business, because the IIF tag will not be able to appropriately parse its parameters, because the offending double quotes will fail to allow the TrueText parameter from evaluating.

One more note, before the solution is provided, is the other reason why escaping is a very good practice. Looking at the previous result, what if [frmMyValue,Form] results in 0? Why should the rendering engine be forced to handle the evaluation of the ACTION tag, even when that tag will not be visible due to the failed condition?

Both of these reasons identify the need for escaping. To do so, you simply need to place a backslash character directly preceding each offending symbol.

{IIF,”[frmMyValue,Form]=1”,
”<a 
\{ACTION, \”Save\”,\”Toolbar\”,,M\}>Save</a>”,
”Incomplete.”}

That will provide the ability for our statement to work perfectly.

Sometimes you must escape more than once
It can’t be said more obviously to the user base, because lets face it – escaping can sometimes be difficult. As a best-practice, I tend to write the content which will need escaping first, then copy and paste it into my favorite text editor, and perform a find and replace on all the offending characters – Replacing { with \{, } with \}, [ with \[, ] with \] and “ with \”. So, when do you need to escape more than once? That’s easy! Whenever your value needs to be embedded more than one layer into a statement. For instance, take the existing example, only stuff the IIF into a SUBQUERY tag. Escapes are processed and removed ONCE for each bounding tag. Below is an example of the physical syntax, and then how the tag would be rendered to provide insight into the reasoning and handling of escaped values. From the previous example, I am replacing the [frmMyValue,Form] tag with the [EntryID] column value, for better demonstration further.

{SUBQUERY,
                Name=”myQuery”,
                Query=”Select * from Lists
”,
                Format
=”\{IIF, \”[EntryID]=1\”,
                                                
\”<a \\{ACTION, \\”Save\\”,\\”Toolbar\\”,,M\\}>Save</a>\”,
                                                
\”Incomplete. \\}”}

See? If we had not escaped, the inner most tags would have rendered first, which would have initially failed the bounding IIF because of the double quote result in the ACTION tag, but moe troubling, if you don’t escape the IIF, you will render it first, the [EntryID] column would fail to parse, and therefore the False condition would immediately replace the content, leaving Format=”Incomplete”. The following steps identify how OpenWebStudio sees and renders the previous statement.

{SUBQUERY,
                Name=”myQuery”,
                Query=”Select * from Lists
”,
                Format=”
\{IIF, \”[EntryID]=1\”,
                                                
\”<a \\{ACTION, \\”Save\\”,\\”Toolbar\\”,,M\\}>Save</a>\”,
                                                
\”Incomplete. \\}”}

First – the Subquery is executed, so lets say the first result, EntryID happens to be 1 from the Lists table. Because the Subquery has been evaluated, the Format tag, which is the result of the Subquery will be immediately unescaped once.

{IIF, ”[EntryID]=1”,
                                                ”<a 
\{ACTION, \”Save\”,\”Toolbar\”,,M\}>Save</a>”,
                                                ”Incomplete.
 ”}

Next, the inner tags are processed. First [EntryID] is evaluated as 1 , which renders the TrueText, unescaping it once.

<a {ACTION, ”Save”,”Toolbar”,,M}>Save</a>

Finally, the ACTION tag is rendered, leaving us with the appropriate __doPostBack link to broadcast our message.

Tip: You can never go wrong with quotes.  They really help in developing more complex statements.  Also, don't forget about the escape (\) character.

Average ( Ratings):
 
Want to help out?
 
 

New York, NY • Baltimore, MD • Vienna, VA • St. Louis, MO • Seattle, WA • info@openwebstudio.com

Bookmark & Share Bookmark and Share