You can address the problem of converting smart quotes – and any other content - in your application if you control the code. What if you’re using third-party software for which you do not have the code? Or what if it is your code but the “defect” is so low on the priority list that you won’t get to it until the year 2020?

Dealing with Microsoft smart quotes is a fact of life for developers. Almost every developer out there has a server-side script/function they use to strip them out of user-generated content and replace them with web-friendly HTML entities instead. But handling smart quotes in application code isn’t always possible or as high a priority as other tasks. If you were looking for a way to address smart quotes once and for all, across multiple applications with one, centralized simple method then a network-side scripting solution may be the answer.



The solutions available today to address this annoyance are many but almost always involve either some client-side process or script, or the modification of server-side applications to recognize and replace the smart quotes with “dumb” HTML representations instead.

Solutions that require modification of the application work just fine, but must be implemented in every application for which such functionality is required. Another option is to simply enforce a “don’t use Microsoft tools to create web-based content.” That policy is likely to go over like a box of rocks as Microsoft tools are pervasive throughout most enterprise organizations. 

blockquote Our department spends a lot of time pasting out of Word and into MT, and smart/curly quotes come out as question marks in some browsers. I was teaching staff to save as text first, open that in SimpleText or NotePad, and paste from there. They hated me for it. – forum post at SixApart discussing the problem of Microsoft “Smart Quotes” and how to get rid of them 

In some situations there may be no viable solution other than a process similar to the one described in the forums at SixApart because you do not have access to the source code for the application.


There is another solution to this problem, one that doesn’t require modifying the applications nor attempting to foist unenforceable policies on users nor requiring users to install or remember to use client-side plug-ins: network-side scripting. Using a network-side script on an application delivery controller (load balancer) offers a way to intercept the requests and replace any smart quotes with dumb quotes for all applications it delivers.


1. The client creates the content however they like, and enters it into the web application. It contains smart quotes.

2. The application delivery controller, which is already acting as a proxy for the application, sees the request and performs a search through the content to find all the smart quotes and then replaces them with dumb quotes.

3. The request is sent to the application with the modified content.

Alternatively, the application delivery controller can perform the search and replace of smart quotes with dumb quotes on the response instead.

  1. The client sends a request
  2. The application delivery controller notes the URI and determines the response will need processing
  3. When the response is received by the application delivery controller it executes logic to find all the smart quotes and replace them with their respective HTML entities.

In either case – replacement on request or response - the execution of the network-side script is transparent; neither the user nor the application is necessarily aware of the script and change to the content. The application delivery controller can further be configured such that only the URIs (requests) specifically known to contain content that might include smart quotes will be examined, thus alleviating any potential concerns about the impact of search and replace functionality on performance.

Here’s an example of modifying content on the response. Notice that when the request is received you need to set a flag only if the URI is one for which you know will need to be “scrubbed” of quotes:

when HTTP_REQUEST {   
  set replace_content 0  
  if {[HTTP::uri] contains "/get-user-generated-content/"} {   
    set replace_content 1   
  if {$replace_content == 1} {  
    # Disable the stream filter by default  
    # 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  

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:


# 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::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