Skip to content

Commit

Permalink
Allow equal signs in values
Browse files Browse the repository at this point in the history
See #21.
  • Loading branch information
izolate authored and mockturtl committed Oct 29, 2019
1 parent bc35b01 commit 97f52c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class Parser {
var stripped = strip(line);
if (!_isValid(stripped)) return {};

var sides = stripped.split('=');
var lhs = sides[0];
var idx = stripped.indexOf('=');
var lhs = stripped.substring(0, idx);
var k = swallow(lhs);
if (k.isEmpty) return {};

var rhs = sides[1].trim();
var rhs = stripped.substring(idx + 1, stripped.length).trim();
var quotChar = surroundingQuote(rhs);
var v = unquote(rhs);

Expand Down
11 changes: 11 additions & 0 deletions test/parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void main() {
subj.interpolate_fallback);
test('it handles \${surrounding braces} on vars', subj.interpolate_curlies);

test('it handles equal signs in values', subj.parseOne_equals);
test('it knows quoted # is not a comment', subj.parseOne_pound);
test('it handles quotes in a comment',
subj.parseOne_commentQuote_terminalChar);
Expand Down Expand Up @@ -77,6 +78,16 @@ class ParserTest {
expect(single['foo'], equals('ab#c'));
}

void parseOne_equals() {
var none = _psr.parseOne('foo=bar=qux');
var sing = _psr.parseOne("foo='bar=qux'");
var doub = _psr.parseOne('foo="bar=qux"');

expect(none['foo'], equals('bar=qux'));
expect(sing['foo'], equals('bar=qux'));
expect(doub['foo'], equals('bar=qux'));
}

void interpolate() {
var out = _psr.interpolate(r'a$foo$baz', {'foo': 'bar', 'baz': 'qux'});
expect(out, equals('abarqux'));
Expand Down

0 comments on commit 97f52c8

Please sign in to comment.