[mapserver-dev] Quote escaping in mapfile strings

Daniel Morissette dmorissette at mapgears.com
Tue Jan 11 23:10:49 EST 2011


An issue that keeps coming back every once in a while is the lack of a 
mechanism to escape quotes (') and double quotes (") inside strings in 
mapfiles.

6.0 would be a good time to address this in case the fix implies new 
mapfile rules or limitations.

The first step is to decide on the syntax to escape quotes. Can anyone 
think of a magic solution to this problem that will make everybody happy?

Here are a few thoughts:

1- An obvious approach could be to use C escaping: \' , \" and \\ ... 
but unfortunately that would force the use of double \\ in all windows 
filename paths. I realize that one could use "/" on Windows instead but 
using this approach could cause unnecessary confusion with beginners and 
become a FAQ that comes up more often than the use dummy TEMPLATEs to 
enable queries in MapScript.

2- Another approach could be to use two double quotes ("") to escape a 
double quote, and two single quotes ('') to escape a single quote

e.g.
   "This string contains ""Double Quotes"""
   'This string contains ''Single Quotes'''
   "You don't need to escape single quotes in this string since it uses 
double quotes ("") as delimiter"
   'And the same way "Double Quotes" don't need escaping here'
   "Two ''single quotes'' in this string are not considered an escape 
sequence and remain two individual chars'

/me thinks #2 could work with a minimum of disruption to existing 
mapfiles, unless I missed something. We'd need Steve's opinion on how 
this can be implemented in the parser.

Anyone have better suggestions?

Daniel
-- 
Daniel Morissette
http://www.mapgears.com/


More information about the mapserver-dev mailing list