When creating a column name it's possible to enter whitespace before or after the column name (and probably elsewhere also).
This can happen for example when copy and pasting into the input field or inadvertently hitting the space bar.
MySQL allows this (which is weird)
It should be standard practice to use trim() for anything like this.
If this is allowed by MySQL, shouldn't we give a way to allow trailing whitespaces?
No. MySQL expect people to use the MySQL client, which strips whitespace.
Matti,
I just tried with the MySQL client 5.5.40 by using backticks around the column name. It's true that it complains about a trailing space (error 1166) but the client is happy with a leading space character in the column name. This is confirmed by http://dev.mysql.com/doc/refman/5.6/en/identifiers.html which says "Database, table, and column names cannot end with space characters."
However, I cannot find a valid reason to allow leading spaces even if MySQL allows them so I am in favor of trimming them (at table creation time only).
Last edit: Marc Delisle 2014-12-20
This is the reply from the guys at MySQL:
"When you create column using MySQL command line client and don't put
column name into quotes the client trims white-spaces. So this is bug
in phpMyAdmin, not in MySQL server."
They regard it as a bug, so should we.
The guys at MySQL are not talking about the same thing. Of course when sending a full statement, all whitespace is trimmed. We are talking about the column name itself as entered in a form, and their own documentation admit that leading space is allowed.
Hi,
I think we should allow leading white spaces as MySQL allows it..and strip the trailing one.
I am a new to opensource and would like to contribute to phpmyadmin...should i try to fix it?
Rakesh,
please do. But about leading spaces, apart from MySQL allowing it, what value do you see in allowing them? I only see potential problems with this.
Who in their right mind would intentionally put whitespace before or after a column name?
I did it inadvertently (before) and naturally it lead to errors.
I have not tested this creating tables or other operations, but it should be.
As a developer it is standard practice for me to trim whitespace on any user input.
This is first year developer kinda stuff.
Last edit: Matti Ressler 2014-12-20
Hi Marc,
Thanks for your response. apart from MySQL allowing the leading white space i don't see any other reason.
I also think it would be better to remove both leading and trailing white spaces.
So, I am trimming the spaces and will commit in a while.
Thanks
Fix: https://github.com/phpmyadmin/phpmyadmin/commit/8415dd4d35aec404e9e5add88126388c1b6d5175
Found another problem with this today. I inadvertently added a comma at the end of a column name (copy and paste from a PDF file), phpMyAdmin and MySQL both accepted it.
Matti,
A space was something clearly inappropriate, but I don't think we will be able to decide which other character is acceptable or not.