This repository was archived by the owner on Oct 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Amazon.IonDotnet.Tests/Internals
Amazon.IonDotnet/Internals/Text Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,21 @@ public void Cleanup()
4646 this . sw . Dispose ( ) ;
4747 }
4848
49+ [ TestMethod ]
50+ [ DataRow ( "0.2" ) ]
51+ [ DataRow ( "2.d-1" ) ]
52+ [ DataRow ( "2d-1" ) ]
53+ public void TestInvalidJsonDecimalFromIon ( string decimalString )
54+ {
55+ var bigDecimal = BigDecimal . Parse ( decimalString ) ;
56+
57+ value . SetField ( "value" , factory . NewDecimal ( bigDecimal ) ) ;
58+ var reader = IonReaderBuilder . Build ( value ) ;
59+ jsonWriter . WriteValues ( reader ) ;
60+
61+ Assert . AreEqual ( "{\" value\" :2e-1}" , this . sw . ToString ( ) ) ;
62+ }
63+
4964 [ TestMethod ]
5065 public void TestGenericNull ( )
5166 {
Original file line number Diff line number Diff line change @@ -218,6 +218,16 @@ public override void WriteDecimal(BigDecimal value)
218218 {
219219 var decimalString = value . ToString ( ) ;
220220 decimalString = decimalString . Replace ( 'd' , 'e' ) ;
221+
222+ // Since Ion Decimal allows an exponent integer following '.' (e.g. 2.d-1) while JSON doesn't, we
223+ // should make sure JSON down converter doesn't write any decimal number with '.' immediately
224+ // followed by 'e'.
225+ var index = decimalString . IndexOf ( ".e" , 0 ) ;
226+ if ( index != - 1 )
227+ {
228+ decimalString = decimalString . Remove ( index , 1 ) ;
229+ }
230+
221231 this . textWriter . Write ( decimalString ) ;
222232 }
223233 else
You can’t perform that action at this time.
0 commit comments