Maria Rosi
Maria Rosi

Reputation: 11

Escape single and double quote in TCL

I am using the following script , but it is throwing error message
tcl;

eval {
     add command "Audit Param"\
     setting "Error : Part's and Spec's desc contains \"OBS\" or \"REPLACE\"" "(Reference No)"\
     user all;
}  

It is showing error as : Expected word got 'and'.
I tried with Part\'s, but still not working. How to escape both single and double quote , if it is having both?

Upvotes: 1

Views: 8894

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137567

Single quote and Tcl

In Tcl itself, the single quote character (') has no special meaning at all. It's just an ordinary character like comma (,) or period (.). (Well, except commas have special meaning in expressions and periods are used in floating point values and Tk widget names. Single quote has no meaning at all by comparison.) With what you have written, any special meaning (and hence any need to quote) is limited to the add command.

Complex quoting situations are often resolved in Tcl by using a different quoting strategy. In particular, putting things in braces disables all substitutions (except backslash-newline-whitespace collapsing). This lets me write the equivalent to what you've written as:

add command "Audit Param" \
      setting {Error : Part's and Spec's desc contains "OBS" or "REPLACE"} \
      "(Reference No)" user all

Any complaint here is coming from inside that code and is not in the code as written per se. (The eval { ... } adds nothing. Nor does it incur a penalty other than making your code slightly harder to read.)

The real problem

At a very loose guess, that problem string is being used inside an SQL statement with direct string substitution instead of prepared parameters; that could produce that sort of error message. Check the contents of the global errorInfo variable after the failure happens to get a stack trace that can help pin down what went wrong; that might help you see where inside things the code is failing. If it is a piece of naughty SQL, there is code to fix because you've got something that is vulnerable to SQL injection problems (which might or might not be a security problem, depending on the exposure of that command). And if that's the case, doubling up each single quote (changing ' to '') ought to work around the problem in the short run.

Upvotes: 4

Related Questions