diff --git a/client/mysql.cc b/client/mysql.cc index 635973e946c..1223a952264 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -154,6 +154,8 @@ static char mysql_charsets_dir[FN_REFLEN+1]; static const char *xmlmeta[] = { "&", "&", "<", "<", + ">", ">", + "\"", """, 0, 0 }; static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; @@ -2116,13 +2118,11 @@ print_table_data_xml(MYSQL_RES *result) (void) tee_fputs("\n \n", PAGER); for (uint i=0; i < mysql_num_fields(result); i++) { - tee_fprintf(PAGER, "\t<%s>", (fields[i].name ? - (fields[i].name[0] ? fields[i].name : - "   ") : "NULL")); + tee_fprintf(PAGER, "\t"); xmlencode_print(cur[i], lengths[i]); - tee_fprintf(PAGER, "\n", (fields[i].name ? - (fields[i].name[0] ? fields[i].name : - "   ") : "NULL")); + tee_fprintf(PAGER, "\n"); } (void) tee_fputs(" \n", PAGER); } diff --git a/mysql-test/r/client_xml.result b/mysql-test/r/client_xml.result new file mode 100644 index 00000000000..b6cebab98e1 --- /dev/null +++ b/mysql-test/r/client_xml.result @@ -0,0 +1,75 @@ +create table t1 ( +`a&b` int, +`ab` text +); +insert into t1 values (1, 2, 'a&b ab'); + + + + + 1 + 2 + a&b a<b a>b + + + + + + + + + + + + + + 1 + 2 + a&b a<b a>b + + + + + + + + + 1 + + + + + + + 1 + + + + + + + 0 + + + + + + + 1 + + + + + + + NULL + + +drop table t1; diff --git a/mysql-test/t/client_xml.test b/mysql-test/t/client_xml.test new file mode 100644 index 00000000000..3628a510557 --- /dev/null +++ b/mysql-test/t/client_xml.test @@ -0,0 +1,18 @@ +# Test of the xml output of the 'mysql' and 'mysqldump' clients -- makes +# sure that basic encoding issues are handled properly +create table t1 ( + `a&b` int, + `ab` text +); +insert into t1 values (1, 2, 'a&b ab'); +--exec $MYSQL --xml test -e 'select * from t1' +--exec $MYSQL_DUMP --xml test + +--exec $MYSQL --xml test -e 'select count(*) from t1' +--exec $MYSQL --xml test -e 'select 1 < 2 from dual' +--exec $MYSQL --xml test -e 'select 1 > 2 from dual' +--exec $MYSQL --xml test -e 'select 1 & 3 from dual' +--exec $MYSQL --xml test -e 'select null from dual' + +drop table t1;