neilw
12-09-2008, 04:51 PM
I have a call to wiki.getsearch() that looks something like this:
var results=wiki.getsearch(searchTerm .. ' AND path:('.. searchPath ..')');
It failed because, as I eventually figured out, there were colons in searchPath, which the search engine Did Not Like. So I tried applying string.escape():
var results=wiki.getsearch(searchTerm .. ' AND path:('.. string.escape(searchPath) ..')');
This still fails; either string.escape() does not consider the colon to be an escapable character, or else the backslashes are getting swallowed somewhere. My eventual fix was to add
string.replace(searchPath, ':', '\\:')
However, this is a band-aid at best, and I simply wait to discover the next character that breaks the code.
So: is there any reliable way to escape the characters in a search query?
var results=wiki.getsearch(searchTerm .. ' AND path:('.. searchPath ..')');
It failed because, as I eventually figured out, there were colons in searchPath, which the search engine Did Not Like. So I tried applying string.escape():
var results=wiki.getsearch(searchTerm .. ' AND path:('.. string.escape(searchPath) ..')');
This still fails; either string.escape() does not consider the colon to be an escapable character, or else the backslashes are getting swallowed somewhere. My eventual fix was to add
string.replace(searchPath, ':', '\\:')
However, this is a band-aid at best, and I simply wait to discover the next character that breaks the code.
So: is there any reliable way to escape the characters in a search query?