mirror of
https://github.com/java-james/flutter_dotenv.git
synced 2025-07-15 05:53:52 +08:00
fix: change regex lookbehind to group (#29)
fixes runtime errors in safari
This commit is contained in:
32
CHANGELOG.md
32
CHANGELOG.md
@ -9,6 +9,10 @@ Release notes are available on [github][notes].
|
||||
[pub-semver-readme]: https://pub.dartlang.org/packages/pub_semver
|
||||
[notes]: https://github.com/java-james/flutter_dotenv/releases
|
||||
|
||||
### 4.0.0-nullsafety.1
|
||||
|
||||
- [fix] Remove lookbehind regex to support safari browser
|
||||
|
||||
4.0.0-nullsafety.0
|
||||
-----
|
||||
|
||||
@ -21,20 +25,20 @@ Release notes are available on [github][notes].
|
||||
- [new] Migrate to null safety
|
||||
- [new] Create unit test cases for parse
|
||||
|
||||
|
||||
#### 3.1.0
|
||||
### 3.1.0
|
||||
|
||||
- [new] Allow merging with a custom map on load
|
||||
|
||||
#### 3.0.2
|
||||
### 3.0.2
|
||||
|
||||
- [chore] Format code with dart fmt
|
||||
|
||||
#### 3.0.1
|
||||
### 3.0.1
|
||||
|
||||
- [docs] Use secure links
|
||||
|
||||
#### 3.0.0
|
||||
3.0.0
|
||||
-----
|
||||
|
||||
- [new] Merge with Platform.Environment
|
||||
- [new] Throw precise errors
|
||||
@ -42,19 +46,19 @@ Release notes are available on [github][notes].
|
||||
- [new] Improved Parsing
|
||||
- [docs] Example project
|
||||
|
||||
#### 2.1.0
|
||||
### 2.1.0
|
||||
|
||||
- [new] Support '=' sign in value
|
||||
|
||||
#### 2.0.3
|
||||
### 2.0.3
|
||||
|
||||
- [fix] Warning when using with flutter_test
|
||||
|
||||
#### 2.0.2
|
||||
### 2.0.2
|
||||
|
||||
- [fix] Flutter 1.9.5 compatibility ensure binding was initialized
|
||||
|
||||
#### 2.0.1
|
||||
### 2.0.1
|
||||
|
||||
- [docs] tweak app description
|
||||
- [fix] increase meta version range
|
||||
@ -81,16 +85,15 @@ Release notes are available on [github][notes].
|
||||
|
||||
- [fix] allow braces with `${var}` substitution [#10][]
|
||||
|
||||
0.1.3
|
||||
-----
|
||||
### 0.1.3
|
||||
|
||||
- [new] add command-line interface [#7][], [#8][]
|
||||
- [deps] add [args][]@v0.13
|
||||
|
||||
[args]: https://pub.dartlang.org/packages/args
|
||||
|
||||
0.1.2
|
||||
-----
|
||||
### 0.1.2
|
||||
|
||||
|
||||
- [new] support variable substitution from `Platform.environment` [#6][]
|
||||
- [deps] drop [logging][]
|
||||
@ -103,8 +106,7 @@ Release notes are available on [github][notes].
|
||||
|
||||
- [fix] whitespace causes quotes not to be stripped
|
||||
|
||||
0.1.1
|
||||
-----
|
||||
### 0.1.1
|
||||
|
||||
- [deprecated] `Parser` internals will become private. [#3][]
|
||||
- `#unquote`, `#strip`, `#swallow`, `#parseOne`, `#surroundingQuote`, `#interpolate`
|
||||
|
@ -3,7 +3,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart' as dotenv;
|
||||
|
||||
Future main() async {
|
||||
await dotenv.load(mergeWith: {
|
||||
await dotenv.load(fileName: "assets/.env", mergeWith: {
|
||||
'TEST_VAR': '5',
|
||||
}); // mergeWith optional, you can include Platform.environment for Mobile/Desktop app
|
||||
|
||||
|
@ -4,9 +4,9 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_dotenv/src/parser.dart';
|
||||
|
||||
import 'errors.dart';
|
||||
import 'parser.dart';
|
||||
|
||||
/// Loads environment variables from a `.env` file.
|
||||
///
|
||||
|
@ -6,8 +6,7 @@ class Parser {
|
||||
static final _comment = RegExp(r'''#[^'"]*$''');
|
||||
static final _commentWithQuotes = RegExp(r'''#.*$''');
|
||||
static final _surroundQuotes = RegExp(r'''^(["'])(.*?[^\\])\1''');
|
||||
static final _bashVar =
|
||||
RegExp(r'(?<=^|[^\\])(\$)(?:{)?([a-zA-Z_][\w]*)+(?:})?');
|
||||
static final _bashVar = RegExp(r'''(\\)?(\$)(?:{)?([a-zA-Z_][\w]*)+(?:})?''');
|
||||
|
||||
/// [Parser] methods are pure functions.
|
||||
const Parser();
|
||||
@ -52,9 +51,13 @@ class Parser {
|
||||
/// Substitutes $bash_vars in [val] with values from [env].
|
||||
String interpolate(String val, Map<String, String?> env) =>
|
||||
val.replaceAllMapped(_bashVar, (m) {
|
||||
var k = m.group(2)!;
|
||||
if ((m.group(1) ?? "") == "\\") {
|
||||
return m.input.substring(m.start, m.end);
|
||||
} else {
|
||||
var k = m.group(3)!;
|
||||
if (!_has(env, k)) return '';
|
||||
return env[k]!;
|
||||
}
|
||||
});
|
||||
|
||||
/// If [val] is wrapped in single or double quotes, returns the quote character.
|
||||
|
50
pubspec.lock
50
pubspec.lock
@ -28,28 +28,28 @@ packages:
|
||||
name: async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.5.0-nullsafety.3"
|
||||
version: "2.5.0"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: boolean_selector
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0-nullsafety.3"
|
||||
version: "2.1.0"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: characters
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0-nullsafety.5"
|
||||
version: "1.1.0"
|
||||
charcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: charcode
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0-nullsafety.3"
|
||||
version: "1.2.0"
|
||||
cli_util:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -63,14 +63,14 @@ packages:
|
||||
name: clock
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0-nullsafety.3"
|
||||
version: "1.1.0"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.15.0-nullsafety.5"
|
||||
version: "1.15.0"
|
||||
convert:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -98,7 +98,7 @@ packages:
|
||||
name: fake_async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0-nullsafety.3"
|
||||
version: "1.2.0"
|
||||
file:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -157,7 +157,7 @@ packages:
|
||||
name: js
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.3-nullsafety.3"
|
||||
version: "0.6.3"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -171,14 +171,14 @@ packages:
|
||||
name: matcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.10-nullsafety.3"
|
||||
version: "0.12.10"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0-nullsafety.6"
|
||||
version: "1.3.0"
|
||||
mime:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -220,21 +220,21 @@ packages:
|
||||
name: path
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0-nullsafety.3"
|
||||
version: "1.8.0"
|
||||
pedantic:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.10.0-nullsafety.3"
|
||||
version: "1.11.0"
|
||||
pool:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pool
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.5.0-nullsafety.3"
|
||||
version: "1.5.0"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -281,84 +281,84 @@ packages:
|
||||
name: source_map_stack_trace
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0-nullsafety.4"
|
||||
version: "2.1.0"
|
||||
source_maps:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_maps
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.10.10-nullsafety.3"
|
||||
version: "0.10.10"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_span
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0-nullsafety.4"
|
||||
version: "1.8.0"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stack_trace
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.10.0-nullsafety.6"
|
||||
version: "1.10.0"
|
||||
stream_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_channel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0-nullsafety.3"
|
||||
version: "2.1.0"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: string_scanner
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0-nullsafety.3"
|
||||
version: "1.1.0"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: term_glyph
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0-nullsafety.3"
|
||||
version: "1.2.0"
|
||||
test:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: test
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.16.0-nullsafety.17"
|
||||
version: "1.16.5"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.19-nullsafety.6"
|
||||
version: "0.2.19"
|
||||
test_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_core
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.12-nullsafety.15"
|
||||
version: "0.3.15"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: typed_data
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0-nullsafety.5"
|
||||
version: "1.3.0"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_math
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0-nullsafety.5"
|
||||
version: "2.1.0"
|
||||
vm_service:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: flutter_dotenv
|
||||
version: 4.0.0-nullsafety.0
|
||||
version: 4.0.0-nullsafety.1
|
||||
description: Easily configure any flutter application with global variables using a `.env` file.
|
||||
author: java-james <james-collins@hotmail.co.nz>
|
||||
homepage: https://github.com/java-james/flutter_dotenv
|
||||
|
@ -1,6 +1,6 @@
|
||||
FOO=foo
|
||||
BAR=bar
|
||||
FOOBAR=\$FOO$BAR
|
||||
FOOBAR=\$FOO${FOO}$BAR
|
||||
ESCAPED_DOLLAR_SIGN="\$1000"
|
||||
ESCAPED_QUOTE='\''
|
||||
|
||||
|
@ -7,13 +7,13 @@ void main() {
|
||||
setUp(() {
|
||||
print(Directory.current.toString());
|
||||
dotenv.testLoad(
|
||||
fileInput: File('.env')
|
||||
fileInput: File('test/.env')
|
||||
.readAsStringSync()); //, mergeWith: Platform.environment
|
||||
});
|
||||
test('able to load .env', () {
|
||||
expect(dotenv.env['FOO'], 'foo');
|
||||
expect(dotenv.env['BAR'], 'bar');
|
||||
expect(dotenv.env['FOOBAR'], '\$FOObar');
|
||||
expect(dotenv.env['FOOBAR'], '\$FOOfoobar');
|
||||
expect(dotenv.env['ESCAPED_DOLLAR_SIGN'], '\$1000');
|
||||
expect(dotenv.env['ESCAPED_QUOTE'], "'");
|
||||
expect(dotenv.env['BASIC'], 'basic');
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter_dotenv/src/parser.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
const ceil = 100000;
|
||||
@ -100,8 +100,8 @@ void main() {
|
||||
expect(out, equals({'foo': 'bar'}));
|
||||
});
|
||||
test('it substitutes known variables into other values', () {
|
||||
var out = _psr.parse(['foo=bar', r'baz=super$foo']);
|
||||
expect(out, equals({'foo': 'bar', 'baz': 'superbar'}));
|
||||
var out = _psr.parse(['foo=bar', r'baz=super$foo${foo}']);
|
||||
expect(out, equals({'foo': 'bar', 'baz': 'superbarbar'}));
|
||||
});
|
||||
test('it discards surrounding quotes', () {
|
||||
var out = _psr.parse([r"foo = 'bar'", r'export baz="qux"']);
|
||||
|
Reference in New Issue
Block a user