From a561c3015f98ce761eb5dd29f59471a902beb70f Mon Sep 17 00:00:00 2001 From: Steve Hamblett Date: Sun, 30 Jun 2024 10:51:59 +0100 Subject: [PATCH] Issue 62 - final fix --- lib/src/value/internal.dart | 4 ++-- test/issue62/issue62_test.dart | 18 ++++++++---------- test/json_encoder_test.dart | 14 +++++++++----- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/src/value/internal.dart b/lib/src/value/internal.dart index 6c99d4b..03e2aeb 100644 --- a/lib/src/value/internal.dart +++ b/lib/src/value/internal.dart @@ -102,14 +102,14 @@ mixin CborValueMixin implements CborValue { toJsonInternal( {}, ToJsonOptions( - encoding: JsonBytesEncoding.base64Url, + encoding: JsonBytesEncoding.base16, allowMalformedUtf8: allowMalformedUtf8, substituteValue: substituteValue, ), ); JsonBytesEncoding? get expectedConversion { - var retVal = JsonBytesEncoding.base64Url; + var retVal = JsonBytesEncoding.base16; for (final tag in tags.reversed) { switch (tag) { case CborTag.expectedConversionToBase16: diff --git a/test/issue62/issue62_test.dart b/test/issue62/issue62_test.dart index 0371704..96a785f 100644 --- a/test/issue62/issue62_test.dart +++ b/test/issue62/issue62_test.dart @@ -10,15 +10,13 @@ import 'package:cbor/cbor.dart'; import 'package:test/test.dart'; void main() { - test( - 'Weird JSON conversion', - () async { - final currDir = Directory.current.path; - final f = File('$currDir/test/issue62/raw.txt'); - final decoded = await f.openRead().transform(cbor.decoder).single; - expect(decoded.toString().isNotEmpty, isTrue); - final jsonEncoder = CborJsonEncoder(); - final json = jsonEncoder.convert(decoded); - print(json); + test('Weird JSON conversion', () async { + final currDir = Directory.current.path; + final f = File('$currDir/test/issue62/raw.txt'); + final decoded = await f.openRead().transform(cbor.decoder).single; + expect(decoded.toString().isNotEmpty, isTrue); + final jsonEncoder = CborJsonEncoder(); + final json = jsonEncoder.convert(decoded); + print(json); }); } diff --git a/test/json_encoder_test.dart b/test/json_encoder_test.dart index a4c4a49..ae52753 100644 --- a/test/json_encoder_test.dart +++ b/test/json_encoder_test.dart @@ -25,19 +25,23 @@ void main() { }); test('18446744073709551615', () { - expect(encode(BigInt.parse('18446744073709551615')), '"__________8"'); + expect( + encode(BigInt.parse('18446744073709551615')), '"FFFFFFFFFFFFFFFF"'); }); test('18446744073709551616', () { - expect(encode(BigInt.parse('18446744073709551616')), '"AQAAAAAAAAAA"'); + expect( + encode(BigInt.parse('18446744073709551616')), '"010000000000000000"'); }); test('-18446744073709551616', () { - expect(encode(BigInt.parse('-18446744073709551616')), '"~__________8"'); + expect( + encode(BigInt.parse('-18446744073709551616')), '"~FFFFFFFFFFFFFFFF"'); }); test('-18446744073709551617', () { - expect(encode(BigInt.parse('-18446744073709551617')), '"~AQAAAAAAAAAA"'); + expect(encode(BigInt.parse('-18446744073709551617')), + '"~010000000000000000"'); }); test('-1', () { @@ -113,7 +117,7 @@ void main() { }); test('4 bytes', () { - expect(encode(Uint8List.fromList([0x1, 0x2, 0x3, 0x4])), '"AQIDBA"'); + expect(encode(Uint8List.fromList([0x1, 0x2, 0x3, 0x4])), '"01020304"'); }); test('Quoted backslash', () {