Bug #38731 mysql client too greedy on NO_BACKSLASH_ESCAPES
Submitted: 11 Aug 2008 21:33 Modified: 14 Oct 2008 10:43
Reporter: Hartmut Holzgraefe Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:>=5.0.25; >= 5.1.12 OS:Any
Assigned to: Assigned Account
Triage: Triaged: D2 (Serious)

[11 Aug 2008 21:33] Hartmut Holzgraefe
Description:
NO_BACKSLASH_ESCAPES is defined as 

  Disable the use of the backslash character (“\”)
  as an escape character within strings.

The fix for bug #20103 "Escaping with backslash does not work as expected"
was implemented too greedy though in that it not only changes the behavior
of backslashes within strings but in general, so disabling command shortcuts
like \G or \C (which in turn leads to bug #36391 "mysqlbinlog creates invalid charset statements")

How to repeat:
Current behavior:

  mysql> SET @@session.sql_mode='NO_BACKSLASH_ESCAPES';
  Query OK, 0 rows affected (0.00 sec)

  mysql> SELECT '\';
  +---+
  | \ |
  +---+
  | \ | 
  +---+
  1 row in set (0.00 sec)

  mysql> SELECT '\'\G
      -> 

Expected behavior:

  mysql> SELECT '\'\G
  *************************** 1. row ***************************
  \: \
  1 row in set (0.00 sec)

Suggested fix:
=== modified file 'client/mysql.cc'
--- client/mysql.cc	2008-07-22 17:41:26 +0000
+++ client/mysql.cc	2008-08-11 20:59:36 +0000
@@ -2042,9 +2042,9 @@ static bool add_line(String &buffer,char
     }
 #endif
     if (!*ml_comment && inchar == '\\' &&
-        !(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES))
+        !(*in_string && (mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)))
     {
-      // Found possbile one character command like \c
+      // Found possible one character command like \c
 
       if (!(inchar = (uchar) *++pos))
 	break;				// readline adds one '\'