Menu

#4659 (ok 4.3.3) Leading and trailing whitespace in column name

4.3.2
fixed
None
1
2014-12-22
2014-12-19
No

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.

Discussion

  • Marc Delisle

    Marc Delisle - 2014-12-19
    • summary: Whitespace --> Whitespace in column name
    • Group: 3.3.7 --> 4.3.2
     
  • Hugues Peccatte

    Hugues Peccatte - 2014-12-19

    If this is allowed by MySQL, shouldn't we give a way to allow trailing whitespaces?

     
    • Matti  Ressler

      Matti Ressler - 2014-12-20

      No. MySQL expect people to use the MySQL client, which strips whitespace.

       
  • Marc Delisle

    Marc Delisle - 2014-12-20

    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
    • Matti  Ressler

      Matti Ressler - 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.

       
      • Marc Delisle

        Marc Delisle - 2014-12-20

        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.

         
  • Rakesh Kumar

    Rakesh Kumar - 2014-12-20

    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?

     
  • Marc Delisle

    Marc Delisle - 2014-12-20

    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.

     
    • Matti  Ressler

      Matti Ressler - 2014-12-20

      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
    • Rakesh Kumar

      Rakesh Kumar - 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

       
  • Marc Delisle

    Marc Delisle - 2014-12-20
    • assigned_to: Marc Delisle
     
  • Marc Delisle

    Marc Delisle - 2014-12-20
    • summary: Whitespace in column name --> (ok 4.3.3) Leading and trailing whitespace in column name
    • status: open --> resolved
    • Priority: 5 --> 1
     
  • Marc Delisle

    Marc Delisle - 2014-12-21
    • Status: resolved --> fixed
     
  • Matti  Ressler

    Matti Ressler - 2014-12-21

    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.

     
  • Marc Delisle

    Marc Delisle - 2014-12-22

    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.