Skip to content

Support Dotenv with quotes and nested quotes - #98

Merged
pedro merged 3 commits into
react-native-config:masterfrom
carlthuringer:dotenv-compatibility
Apr 26, 2017
Merged

Support Dotenv with quotes and nested quotes#98
pedro merged 3 commits into
react-native-config:masterfrom
carlthuringer:dotenv-compatibility

Conversation

@carlthuringer

Copy link
Copy Markdown
Contributor

Addressing #97

When parsing dotenv files, if there's any guide to follow, it's the defacto npm dotenv project

The parsing engine currently supports the following rules:

  • BASIC=basic becomes {BASIC: 'basic'}
  • empty lines are skipped
  • lines beginning with # are treated as comments
  • empty values become empty strings (EMPTY= becomes {EMPTY: ''})
  • single and double quoted values are escaped (SINGLE_QUOTE='quoted' becomes {SINGLE_QUOTE: "quoted"})
  • new lines are expanded if in double quotes (MULTILINE="new\nline" becomes
    {MULTILINE: 'new
    line'}
  • inner quotes are maintained (think JSON) (JSON={"foo": "bar"} becomes {JSON:"{"foo": "bar"}")

This PR implements a more sophisticated matching using a regular expression. This allows the parser to handle all the cases presented in the dotenv node package.

@carlthuringer

Copy link
Copy Markdown
Contributor Author

I'm no groovy/java developer, so I can't actually figure out the android code. I tried several ways to test JAVA regexes online but no real results. I think someone who knows how those work can easily take my pattern and apply it to the gradle script.

@janoist1

Copy link
Copy Markdown

You can escape quotes, that helped me passing JSON in.

@pedro

pedro commented Apr 26, 2017

Copy link
Copy Markdown
Contributor

You rock, thank you!

@pedro
pedro merged commit f8d9a7e into react-native-config:master Apr 26, 2017
@pedro

pedro commented Apr 26, 2017

Copy link
Copy Markdown
Contributor

Ah hmm testing some stuff before releasing I noticed this dropped support for unquoted values (the 1st example in https://regex101.com/r/SLdbes/1). I made the quotes optional for now to not break existing apps. Do you think we should explicitly ignore these?

pedro added a commit that referenced this pull request Apr 26, 2017
@carlthuringer
carlthuringer deleted the dotenv-compatibility branch May 19, 2017 16:01
venus-heaven pushed a commit to venus-heaven/config-React-native that referenced this pull request Mar 11, 2024
dev-arrow added a commit to dev-arrow/react-native-config that referenced this pull request Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants