Coder Social home page Coder Social logo

dotenv-editor's People

Contributors

caneco avatar michaeldyrynda avatar sixlive avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dotenv-editor's Issues

DotenvEditor::format() should quotes values when they contain certain characters

When exporting a .env file, values are never wrapped in quotes. When a value contains certain characters, like =, $, or \n (new line), this causes the resultant contents to be invalid.

E.g.

<?php

use sixlive\DotenvEditor\DotenvEditor;

include "vendor/autoload.php";

$editor = new DotenvEditor;

$editor->load(__DIR__.'/.env');

$editor->heading('Examples');
$editor->set('A', 't9maWr2GA6=');
$editor->set('B', 'this-should-be-$ingle-quoted');
$editor->set('C', 'multi
line
should be
quoted');

$editor->save();

Results in

# Examples
A=t9maWr2GA6=
B=this-should-be-$ingle-quoted
C=multi
line
should be
quoted

This is not a valid dotenv file and, for example, Laravel will not be able to load it.

? sprintf('%s=%s', $key, $item)

There needs to be some different preparation of values, that need quoting, prior to writing them to the .env file.

For example:

  1. If contains =, #, or a $ as part of variable/command substitution (e.g. "$(bleh)" or "${FOO}") then wrap in double quotes
  2. If contains $ not used for variable/command substitution, then wrap in single quotes
  3. If contains new line character (\n) either wrap in double quotes and\or convert the new line characters to a \n literal string

The edit of the .env file removes the application key

What are the steps to reproduce this issue?

  1. Write any value to an .env file

What happens?

APP_KEY=base64... gets reset to just APP_KEY

What were you expecting to happen?

Keep the value of APP_KEY

Any logs, error output, etc?

No

Any other comments?

No

What versions are you using?

Operating System: OSX Mojave
Package Version: v1.1.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.