Skip to content

[2.6.0] Got DB connection error after update #336

Closed

Description

@makersm

Hi, I'm using DB connection using .env file.
.env file looks like below :

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=homestead_h
DB_USERNAME=homestead
DB_PASSWORD=secret!@#

and I got Access denied for user ~~ error.
After revert phpdotenv's version 2.6.0 to 2.5.2, everything works fine.

Activity

  1. zhouzyc commented on Jan 29, 2019

    @zhouzyc

    I also have a connection error. After updating, the password has a # number.

  2. zhouzyc commented on Jan 29, 2019

    @zhouzyc

    Hi, I'm using DB connection using .env file.
    .env file looks like below :

    DB_CONNECTION=mysql
    DB_HOST=localhost
    DB_PORT=3306
    DB_DATABASE=homestead_h
    DB_USERNAME=homestead
    DB_PASSWORD=secret!@#
    

    and I got Access denied for user ~~ error.
    After revert phpdotenv's version 2.6.0 to 2.5.2, everything works fine.
    With the new configuration file:
    DB_CONNECTION=mysql
    DB_HOST=localhost
    DB_PORT=3306
    DB_DATABASE=homestead_h
    DB_USERNAME=homestead
    DB_PASSWORD=”secret!@#“

  3. robtesch commented on Jan 29, 2019

    @robtesch

    Same issue with Laravel project. Tried every possible combination of quotes and no quotes. My password has a # in it if that's any help.

  4. zhouzyc commented on Jan 29, 2019

    @zhouzyc

    @robtesch
    have a try
    DB_PASSWORD=secret!@# ->DB_PASSWORD=”secret!@#“

  5. erikscheepers commented on Jan 29, 2019

    @erikscheepers

    Same error here, also a # in the password. Putting the password between quotes fixes the issue. My password looks like se#cret (no # at the end).

  6. GrahamCampbell commented on Jan 29, 2019

    @GrahamCampbell
    Collaborator

    Thanks for the report. It looks like we're missing some tests.

  7. GrahamCampbell commented on Jan 29, 2019

    @GrahamCampbell
    Collaborator

    The new version is parsing the hash as a comment.

  8. GrahamCampbell commented on Jan 29, 2019

    @GrahamCampbell
    Collaborator

    I'm prepping a fix now.

  9. GrahamCampbell commented on Jan 29, 2019

    @GrahamCampbell
    Collaborator

    Please let me know if #338 fixes your issue. :)

  10. GrahamCampbell commented on Jan 29, 2019

    @GrahamCampbell
    Collaborator

    I've released v2.6.1 with the parser fixes.

  11. robtesch commented on Jan 29, 2019

    @robtesch

    @GrahamCampbell thanks very much, that fixed it. Out of interest, for future (v3+) how should we do it? Do we need to escape some chars?

  12. GrahamCampbell commented on Jan 29, 2019

    @GrahamCampbell
    Collaborator

    The three differences are:

    1. For unquoted strings, as soon as there's a hash, it's treated as a comment start.
    2. We're being stricter about invalid escape sequences within quoted strings.
    3. We're no longer trimming the parsed values of quoted strings.
    input value 2.5.2 2.6.1 3.3.1
    foo#bar foo#bar foo#bar foo
    foo # bar foo foo foo
    "iiiiviiiixiiiiviiii\n" silent failure iiiviiiixiiiiviiii\n fails with invalid escape sequence exception
    "iiiiviiiixiiiiviiii\\n" iiiiviiiixiiiiviiii\n iiiiviiiixiiiiviiii\n iiiiviiiixiiiiviiii\n
    "foo\"bar" foo"bar foo"bar foo"bar
    " foo " foo with whitespace trimmed foo with whitespace trimmed foo with 2 spaces in front and one after

    In double quoted strings, double quotes and backslashes need escaping with a backslash, and in single quoted strings, single quote and backslashes need escaping with a backslash. In v2.5.2, forgetting an escape can lead to odd results due to the regex running out of stack, but this was fixed in 2.6 and 3.3, with 2.6 allowing you to continue after an unescaped backslash, but 3.3 not.

  13. robtesch commented on Jan 29, 2019

    @robtesch

    Good stuff, so just to confirm, even for v3.3+, if the input is:
    "p455w0rd123#"
    it will come out as:
    p455w0rd123#

    No need to escape anything since it's in double quotes and does not contain any double quotes or backslashes.

  14. GrahamCampbell commented on Jan 29, 2019

    @GrahamCampbell
    Collaborator

    Yes, that's correct. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions