Welcome!

If everyone is thinking the same, someone isn't thinking

Lori MacVittie

Subscribe to Lori MacVittie: eMailAlertsEmail Alerts
Get Lori MacVittie via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: Twitter on Ulitzer, Microsoft Developer, CIO/CTO Update, VITO Report

Blog Feed Post

Using Network-Side Scripting to Convert Microsoft Smart Quotes to HTML Entities

You can address the problem of converting smart quotes – and any other content - in your application if you control the code

when HTTP_REQUEST {   
set replace_content 0  
if {[HTTP::uri] contains "/get-user-generated-content/"} {   
set replace_content 1   
}   
}   
when HTTP_RESPONSE {  
if {$replace_content == 1} {  
# Disable the stream filter by default  
STREAM::disable  
# Check if response type is text  
if {[HTTP::header value Content-Type] contains "text" and [HTTP::header "User-Agent"] contains "***"}{  
# Replace   
STREAM::expression "@search-for@replacement@ @search-for@replacement@"  
# Enable the stream filter for this response only  
STREAM::enable  
}  
}  
}

Note: this script won’t actually replace smart quotes, it is provided as a generic example of how the logic in iRules (F5 implementation of network-side scripting) would be used to replace content in a response.

If you just wanted to replace the smart quotes when they are being submitted, you might use an iRule that looks more like this:

when HTTP_REQUEST {

# Check if the request is one we want to mess with
if {[HTTP::path] starts_with "/post-user-generated-content" and [HTTP::method] eq "POST"} {


# Enable the stream profile and set the find/replace strings
STREAM::enable
STREAM::expression "@search-for@replacement@ @search-for@replacement@
   }
}

Again, this is just an example; you’d need to add all the possible values for smart quotes and their respective HTML entities and modify the condition upon which it is executed (i.e. change the URIs to match your application).

The syntax of the network-side script to do the replacement will vary based on the solution you are using. Some solutions depend heavily upon the use of regular expressions to modify content while others may have a mechanism similar to iRules or other programmatic languages. The general logic, however, should remain the same in that you’ll almost certainly use the URI to determine whether you want to find and replace the quotes. It should be noted that you can scan every request and response for the presence of Microsoft smart quotes but this will likely cause a performance hit depending on the size and content of requests/responses being processed.

In both cases, network-side scripting provides you the means by which you can address smart quotes in a non-intrusive, transparent way regardless of whether you have access to the application source code or not. This capability is by no-means limited to just addressing the issue of smart quotes; obviously you can use it to replace just about any content in request and response data you choose. Use it for a comprehensive filtering system that applies organizational policy regarding the use of certain “unacceptable” words across all applications; use it to replace URIs for versioning or migration support; use it for fun on April Fools’ Day for a good laugh (at least on your part).

Network-side scripting can be a powerful tool for addressing common content-based problems that crop up in both custom and packaged applications. Remember it’s available in your arsenal of web application development tools as another option for addressing just about any content-based application quirks you might find in the future.

 

Follow me on Twitter View Lori's profile on SlideShare friendfeed icon_facebook

AddThis Feed Button Bookmark and Share

Related blogs & articles:

More Stories By Lori MacVittie

Lori MacVittie is responsible for education and evangelism of application services available across F5’s entire product suite. Her role includes authorship of technical materials and participation in a number of community-based forums and industry standards organizations, among other efforts. MacVittie has extensive programming experience as an application architect, as well as network and systems development and administration expertise. Prior to joining F5, MacVittie was an award-winning Senior Technology Editor at Network Computing Magazine, where she conducted product research and evaluation focused on integration with application and network architectures, and authored articles on a variety of topics aimed at IT professionals. Her most recent area of focus included SOA-related products and architectures. She holds a B.S. in Information and Computing Science from the University of Wisconsin at Green Bay, and an M.S. in Computer Science from Nova Southeastern University.