diff --git a/client/mysql.cc b/client/mysql.cc
index 9474e4beccc..e4eabe8de33 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -3387,9 +3387,12 @@ print_table_data_html(MYSQL_RES *result)
{
while((field = mysql_fetch_field(result)))
{
- tee_fprintf(PAGER, "
%s | ", (field->name ?
- (field->name[0] ? field->name :
- " ") : "NULL"));
+ tee_fputs("", PAGER);
+ if (field->name && field->name[0])
+ xmlencode_print(field->name, field->name_length);
+ else
+ tee_fputs(field->name ? " " : "NULL", PAGER);
+ tee_fputs(" | ", PAGER);
}
(void) tee_fputs("", PAGER);
}
@@ -3400,7 +3403,7 @@ print_table_data_html(MYSQL_RES *result)
for (uint i=0; i < mysql_num_fields(result); i++)
{
(void) tee_fputs("", PAGER);
- safe_put_field(cur[i],lengths[i]);
+ xmlencode_print(cur[i], lengths[i]);
(void) tee_fputs(" | ", PAGER);
}
(void) tee_fputs("", PAGER);
diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result
index 4affd884753..1945f893f04 100644
--- a/mysql-test/r/mysql.result
+++ b/mysql-test/r/mysql.result
@@ -199,4 +199,5 @@ COUNT (*)
COUNT (*)
1
ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (errno)
+
End of 5.0 tests
diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test
index b2d7400d156..0cdb0ddb653 100644
--- a/mysql-test/t/mysql.test
+++ b/mysql-test/t/mysql.test
@@ -356,4 +356,10 @@ remove_file $MYSQLTEST_VARDIR/tmp/bug31060.sql;
--exec $MYSQL --default-character-set=binary test -e "CONNECT test invalid_hostname" 2>&1
--exec $MYSQL --default-character-set=binary test -e "DELIMITER //" 2>&1
+#
+# Bug #27884: mysql --html does not quote HTML special characters in output
+#
+--exec $MYSQL --html test -e "select '< & >' as \`<\`"
+--echo
+
--echo End of 5.0 tests