Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions third_party/packages/mustache_template/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.2

* Emoji support.

## 2.0.1

* Transfers the package source from https://github.com/jonahwilliams/mustache
Expand Down
9 changes: 6 additions & 3 deletions third_party/packages/mustache_template/lib/src/scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'token.dart';
class Scanner {
Scanner(String source, this._templateName, String? delimiters)
: _source = source,
_itr = source.runes.iterator {
_itr = source.runes.iterator,
_runes = source.runes.toList() {
if (source == '') {
_c = _EOF;
} else {
Expand Down Expand Up @@ -40,6 +41,7 @@ class Scanner {
final String _source;

final Iterator<int> _itr;
final List<int> _runes;
int _offset = 0;
int _c = 0;

Expand Down Expand Up @@ -130,8 +132,9 @@ class Scanner {
while (_peek() != _EOF && test(_peek())) {
_read();
}
final int end = _peek() == _EOF ? _source.length : _offset;
return _source.substring(start, end);
final int end = _peek() == _EOF ? _runes.length : _offset;
final String part = String.fromCharCodes(_runes.sublist(start, end));
return part;
}

void _expect(int expectedCharCode) {
Expand Down
2 changes: 1 addition & 1 deletion third_party/packages/mustache_template/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: mustache_template
description: A templating library that implements the Mustache template specification
repository: https://github.com/flutter/packages/tree/main/third_party/packages/mustache_template
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+mustache_template%22
version: 2.0.1
version: 2.0.2

environment:
sdk: ^3.7.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ void main() {
).renderString(<dynamic, dynamic>{});
expect(output, equals('__'));
});
test('Emoji', () {
final String output = parse(
'Hello! 🖖👍🏽\nBye! 🏳️‍🌈',
).renderString(<dynamic, dynamic>{});
expect(output, equals('Hello! 🖖👍🏽\nBye! 🏳️‍🌈'));
});
});
group('Section', () {
test('Map', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,15 @@ void main() {
]);
});

test('emoji', () {
const String source = 'Hello! 🖖👍🏽🏳️‍🌈\nEmoji';
final Parser parser = Parser(source, 'foo', '{{ }}');
final List<Node> nodes = parser.parse();
expectNodes(nodes, <Node>[
TextNode('Hello! 🖖👍🏽🏳️‍🌈\nEmoji', 0, 20), // End offset includes emoji sizes
]);
});

test('toString', () {
TextNode('foo', 1, 3).toString();
VariableNode('foo', 1, 3).toString();
Expand Down