Skip to content

Commit 2963df6

Browse files
authored
Add missing increment to custom code-page decoder. (dart-archive/convert#62)
* Add missing increment to custom code-page decoder. Fixes dart-lang/convert#47.
1 parent 1dc4a8c commit 2963df6

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

pkgs/convert/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## 3.0.2-dev
1+
## 3.0.2
2+
3+
* Fix bug in `CodePage` class. See issue [#47](https://github.com/dart-lang/convert/issues/47).
24

35
## 3.0.1
46

pkgs/convert/lib/src/codepage.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ CodePageDecoder _createDecoder(String characters) {
262262
throw ArgumentError.value(
263263
characters, "characters", "Must contain 256 characters");
264264
}
265-
result[i] = char;
265+
result[i++] = char;
266266
allChars |= char;
267267
}
268268
if (i < 256) {

pkgs/convert/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: convert
2-
version: 3.0.2-dev
2+
version: 3.0.2
33
description: >-
44
Utilities for converting between data representations.
55
Provides a number of Sink, Codec, Decoder, and Encoder types.

pkgs/convert/test/codepage_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,15 @@ void main() {
6060
var decoded = latin3.decode(encoded, allowInvalid: true);
6161
expect(decoded, latin2text);
6262
});
63+
64+
test("Custom code page", () {
65+
var cp = CodePage("custom", "ABCDEF" + "\uFFFD" * 250);
66+
var result = cp.encode("BADCAFE");
67+
expect(result, [1, 0, 3, 2, 0, 5, 4]);
68+
expect(() => cp.encode("GAD"), throwsFormatException);
69+
expect(cp.encode("GAD", invalidCharacter: 0x3F), [0x3F, 0, 3]);
70+
expect(cp.decode([1, 0, 3, 2, 0, 5, 4]), "BADCAFE");
71+
expect(() => cp.decode([6, 1, 255]), throwsFormatException);
72+
expect(cp.decode([6, 1, 255], allowInvalid: true), "\u{FFFD}B\u{FFFD}");
73+
});
6374
}

0 commit comments

Comments
 (0)